官方文档
https://wiki.lineageos.org/build_guides.html
环境配置
jdk8、Python2.7和repo等参考上篇文章: kali编译aosp和xposed
额外需要安装的依赖:
apt install -y bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev
lineageOS对应的jdk版本:
下载源码
https://mirrors.tuna.tsinghua.edu.cn/help/lineageOS/
mkdir lineage
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b lineage-15.1
等待完成后需要修改.repo/manifests/default.xml文件内容,需要修改的内容请看上面的网站
修改完之后开始同步源码:repo sync
准备一些内核和设备文件
本来执行下面两条命令即可自动下载
source build/envsetup.sh
breakfast oneplus3
但是国内访问github实在太慢了,导致一直报错
有两种方法可以解决(最好两种都用):
- 改hosts来提高下载速度
- 手动下载放到相应目录
第一种方法
参考链接:https://zhuanlan.zhihu.com/p/107334179
vim /etc/hosts
增加如下内容:
# GitHub Start
52.78.231.108 github.com
52.68.31.213 nodeload.github.com
54.180.75.25 api.github.com
13.124.75.135 codeload.github.com
185.199.109.133 raw.github.com
185.199.110.153 training.github.com
# GitHub End
你可以试试ping 52.78.231.108能不能ping通,如果不能。需要按照上面的链接重新找一个ip来替换。
接着运行/etc/init.d/networking restart
之后,就可以运行开始的两条命令下载了
这种方法访问依旧很慢,只是从不动变为了慢慢动
第二种方法
https://github.com/LineageOS/android_device_oneplus_oneplus3
|-------------------------| lineage/device/oneplus/oneplus3
https://github.com/LineageOS/android_device_oppo_common
|--------------------------------| device/oppo/common
https://github.com/LineageOS/android_kernel_oneplus_msm8996
|--------------------------| kernel/oneplus/msm8996
https://github.com/LineageOS/android_packages_resources_devicesettings
|----------|packages/resources
前面是需要下载的文件,后面是需要放置的路径。默认你当前路径是最开始创建的lineage文件夹,如果路径不存在则手动创建。就比如第一个下载完后:
下载的时候需要选择分支,比如我编译的是lineage15.1就需要选这个分支
所有文件下载完成后,就可以执行开头的两个命令了,当然你也可以改一下hosts文件,因为还要访问github对比一下文件的。
如果是其他设备,这个清单在运行breakfast 设备名称
之后便可以在.repo/local_manifests/roomservice.xml
中看到
name为github的路径,前面加上https://github.com/
就是地址了,path为本地路径,也就是下载完的文件要放在哪
提取驱动
https://wiki.lineageos.org/extracting_blobs_from_zips.html#extracting-proprietary-blobs-from-block-based-otas
有两种提取方式:从已经编译的lineage15.1刷机包内提取;从已经刷入lineage15.1的手机提取
我用的是第一种,因为我使用第二种一直在等待设备,我使用adb device
是存在设备的
刷机包下载链接:https://www.celsoazevedo.com/files/android/oneplus3-lineageos/
在其他目录创建一个文件夹来操作,不要污染源码的目录文件。
mkdir /root/oneplus3_blob
cd /root/oneplus3_blob
从lineage15.1刷机包中解压system.transfer.list
和system.new.dat.br
两个文件
apt-get install brotli
# 安装brotli工具
brotli --decompress --output=system.new.dat system.new.dat.br
# br文件转dat文件
下载https://github.com/xpirt/sdat2img
中的sdat2img.py
,然后执行python2 sdat2img.py system.transfer.list system.new.dat system.img
,这会生成一个system.img文件。
接着在当前目录下mkdir system
,然后挂载system.img到system目录下mount system.img system/
接着回到lineage/device/oneplus/oneplus3/目录中执行
./extract-files.sh /root/oneplus3_blob/system
提取完可以卸载那个目录了umount /root/oneplus3_blob/system
提取的时候可能会出现一个错误,没找到/sbin/dashd 这个文件(如下图)
我们需要在已经刷了lineage15.1的一加三手机上提取到这个文件,放到lineage/vendor/oneplus/oneplus3/proprietary/rootfs/sbin/dashd
下,不然后面编译的时候会报这个文件找不到(如下图)
这是我提取的dashd(用于oneplus3的lineage15.1):https://www.lanzoui.com/iSaLAvufrpi
其他设备或系统需要自己提取,用这个可能会出问题。我想知道最开始的时候是怎么编译的,没有刷机包的时候官方是怎么生成这些文件。
开始编译
在编译之前需要先处理一件事,不然会报如下错误(图中圈中部分为实际错误),这个错误折腾了我好久,主要是多线程错误不是显示在最底部,藏的有点深。
解决方法很简单:https://blog.csdn.net/ZLK1214/article/details/113729027
编辑lineage/kernel/oneplus/msm8996/Makefile
文件,在末尾加入HOSTCFLAGS += -fcommon
即可
接着就可以愉快的编译了
export LC_ALL=C
brunch oneplus3
如果你新开过终端需要先执行下面两个命令再编译
source build/envsetup.sh
breakfast oneplus3
不出意外的话就可以看到这样的输出了
最后一行的路径就是刷机包的路径了,这是卡刷包,只需要在twrp下刷入即可。至于刷入后能不能成功开机我就不清楚了,我还没试。