概述
AOSP官方源码,对Nexus 5
仅支持到Android 6.0
,而第三方系统支持Android 11.0
。
由于需要定制系统和内核,故考虑克隆源码,手动编译。
ROM下载地址
[ROM][UNOFFICIAL] LineageOS 18.1 for Nexus 5 (hammerhead) [DISCONTINUED] | XDA Forums
准备
Repo
1 2 3 4
| curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo chmod +x repo sudo mv repo /usr/local/bin/ export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
|
初始化
1 2 3
| mkdir lineage cd lineage repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b lineage-18.1
|
修改xml以使用TUNA镜像
打开.repo/manifests/default.xml
,具体修改见lineageOS 源代码镜像使用帮助
同步源码
使用repo
同步lineage-18.1
源码:
1
| repo sync -c -j4 --force-sync
|
Patches
设置环境变量$LINEAGE_DIR
为源码目录后,执行以下命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| export LINEAGE_DIR=/media/xhy/a5d37cc9-d3a3-43c8-909d-178d70a6598c/Android/source/lineage
echo "Patch SurfaceFlinger" cd $LINEAGE_DIR/frameworks/native git fetch "https://github.com/LineageOS/android_frameworks_native" refs/changes/15/310715/1 && git cherry-pick FETCH_HEAD cd $LINEAGE_DIR/vendor/lineage git fetch "https://github.com/LineageOS/android_vendor_lineage" refs/changes/16/310716/1 && git cherry-pick FETCH_HEAD
echo "Patch QCOM display" cd $LINEAGE_DIR/hardware/qcom/display git fetch https://github.com/z3DD3r/android_hardware_qcom_display lineage-18.1 && git cherry-pick 6efcc49e6a81fdc1e248f5002633f8cad6e6395b^..064cec4d219aa3e4c26f0a281d93f064b9372832
echo "Patch Vold (USB OTG)" cd $LINEAGE_DIR/system/vold git fetch https://github.com/z3DD3r/android_system_vold lineage-18.1 && git cherry-pick eca4855b992868e05f3be34ea9f7c41b565b4e1a^..f5730f872ed7e58a064529346d3e371b9cd4d73f
echo "Patch AOSP Keyboard" cd $LINEAGE_DIR/packages/inputmethods/LatinIME git fetch https://github.com/z3DD3r/android_packages_inputmethods_LatinIME lineage-18.1 && git cherry-pick 7e55f8c6b7257af03891934da329e2f6aea72c67^..6b0819b6373ee18766d8b1846dcf512dd527dc13
echo "Back to LINEAGE_DIR" cd $LINEAGE_DIR
|
下载设备相关文件
使用Local Manifests(推荐)
创建.repo/local_manifests/hammerhead.xml
:
1 2 3 4 5 6
| <?xml version="1.0" encoding="UTF-8"?> <manifest> <project name="z3DD3r/android_device_lge_hammerhead" path="device/lge/hammerhead" remote="github" /> <project name="z3DD3r/android_kernel_lge_hammerhead" path="kernel/lge/hammerhead" remote="github" /> <project name="z3DD3r/android_vendor_lge" path="vendor/lge" remote="github" /> </manifest>
|
然后repo sync -c -j4 --force-sync
即可
PS:proprietary
文件已在android_vendor_lge
中,不需要手动导出
手动克隆
device
1 2
| mkdir device/lge git clone https://github.com/z3DD3r/android_device_lge_hammerhead -b lineage-18.1 device/lge/hammerhead
|
kernel
1 2
| mkdir kernel/lge git clone https://github.com/z3DD3r/android_kernel_lge_hammerhead -b lineage-18.1 device/lge/hammerhead
|
vendor
1
| git clone https://github.com/z3DD3r/android_vendor_lge -b lineage-18.1 vendor/lge
|
编译环境选择
使用Docker容器(推荐)
使用已安装好依赖的镜像,不需要自己配置编译环境
使用docker-lineage:v18.1(推荐)
设置ANDROID_VOL
为源码父目录后,创建容器:
1 2 3 4 5
| export ANDROID_VOL=/media/xhy/a5d37cc9-d3a3-43c8-909d-178d70a6598c/Android docker run --privileged -it \ -v "$ANDROID_VOL/source:/srv/src" \ -v "$ANDROID_VOL/ccache:/srv/ccache" \ xhyeax/docker-lineage:v18.1
|
使用docker-lineage-cicd
docker-lineage-cicd
设置ANDROID_VOL
为源码父目录后,创建容器:
1 2 3 4 5 6 7 8 9 10 11
| export ANDROID_VOL=/media/xhy/a5d37cc9-d3a3-43c8-909d-178d70a6598c/Android docker run --privileged -it \ -e "BRANCH_NAME=lineage-18.1" \ -e "DEVICE_LIST=hammerhead" \ -e "INCLUDE_PROPRIETARY=false" \ -e "CRONTAB_TIME=notnow" \ -v "$ANDROID_VOL/source:/srv/src" \ -v "$ANDROID_VOL/zips:/srv/zips" \ -v "$ANDROID_VOL/logs:/srv/logs" \ -v "$ANDROID_VOL/ccache:/srv/ccache" \ lineageos4microg/docker-lineage-cicd
|
使用错误的定时任务格式,阻止脚本自动编译,输出如下:
1 2 3 4
| lineageos4microg/docker-lineage-cicd Set cache size limit to 50.0 GB "/tmp/buildcron":45: bad minute errors in crontab file, can't install.
|
此时使用VSCode
的Docker
插件,附加容器即可(也可按下Ctrl+C
退出后,重启容器后附加)
PS:还可以将CRONTAB_TIME
设置为0 0 0 1 1
(每年的1月一日),再删除定时任务
本地编译
Build for hammerhead | LineageOS Wiki
安装依赖
1 2 3 4 5 6 7
| apt-get install -y bc bison bsdmainutils build-essential ccache cgpt clang \ curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick \ kmod lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool \ libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 \ libxml2-utils lsof lzop maven openjdk-8-jdk pngcrush procps \ python rsync schedtool squashfs-tools wget xdelta3 xsltproc yasm zip \ zlib1g-dev
|
配置ccache
启用ccache
并设置路径和大小:
1 2 3
| export USE_CCACHE=1 export CCACHE_DIR=/media/xhy/a5d37cc9-d3a3-43c8-909d-178d70a6598c/Android/ccache ccache -M 50G
|
配置
开始编译
打开系统源码目录,执行以下命令编译:
1 2
| source build/envsetup.sh brunch hammerhead
|
碰到的问题
1
| hardware/qcom/display/msm8974/libgralloc/Android.mk: error: gralloc.msm8974: LOCAL_COPY_HEADERS is obsolete
|
原因:hardware/qcom/display
未Patch
解决方案:执行前文Patch
部分的Patch QCOM display
No rule to make target “/hz.h”, needed by ‘kernel/hz.bc’
1
| No rule to make target 'lineage/out/target/product/hammerhead/obj/KERNEL_OBJ/include/config/hz.h', needed by 'kernel/hz.bc'
|
原因:可能是文件缺失
解决方案:repo sync -c -j4 --force-sync
,重新同步源码,从头再来
刷机
刷入TWRP
前往hammerhead-twrp下载最新的TWRP
镜像,并刷入设备
清除数据
如果之前的系统不是LineageOS 18.1
,建议清除数据后刷入,具体操作:
进入TWRP
,选择Wipe
-Advanced Wipe
,清除System
、Data
、Cache
分区数据
刷入系统
将生成的刷机包发送到手机后,使用TWRP
刷入即可
参考
自己动手编译Android(LineageOS)源码
huataihuang/cloud-atlas-draft build_lineageos_for_hammerhead