安装依赖
sudo apt install -y bc bison build-essential curl flex gcc-multilib git git-core gnupg gperf g++-multilib libesd0-dev libgl1-mesa-dev liblz4-tool libncurses5-dev libreadline6-dev libsdl1.2-dev libwxgtk3.0-dev libxml2 libxml2-utils libx11-dev lib32ncurses5-dev lib32z1-dev lzop pngcrush schedtool squashfs-tools unzip xsltproc zip zlib1g-dev
安装Open JDK 8
sudo apt install -y openjdk-8-jdk
设置 git
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
双引号中的 “you@example.com” 填写您的 github 所使用的邮箱。注意格式,不要把双引号去掉。
双引号中的 “Your Name” 填写您的 github 用户名,不要把双引号去掉。
下载源码
新建源码目录
mkdir -p ~/android/los/lineage-16.0
cd ~/android/los/lineage-16.0
下载repo工具,使用清华镜像
mkdir ~/bin
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod a+x !/bin/repo
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
下载repo工具,使用谷歌
mkdir ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
将repo加入环境变量
gedit ~/.profile 在文件最后面加入下面内容
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
source ~/.profile
初始化源码,使用清华镜像,如果不使用镜像可以参考lineageOS官方教程
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b lineage-16.0
打开.repo/manifest.xml,将
<remote name="github"
fetch=".."
review="review.lineageos.org" />
改成
<remote name="github"
fetch="https://github.com/" />
<remote name="lineage"
fetch="https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/"
review="review.lineageos.org" />
将
<remote name="aosp"
fetch="https://android.googlesource.com"
改成
<remote name="aosp"
fetch="https://aosp.tuna.tsinghua.edu.cn"
将
<default revision="..."
remote="github"
改成
<default revision="..."
remote="lineage"
同步源码树(以后只需执行这条命令来同步):
repo sync --no-clone-bundle -f -j16
同步设备专属文件
source build/envsetup.sh
//lithium是xiaomi mix的名称,如果是第一次编译,需要sync同步device代码
breakfast lithium
获取设备专属驱动vendor
- 推荐使用2
###1.利用adb从手机获取
//连接手机,并保证adb命令正常, cd到此目录device/xiaomi/lithium ,如果编译过程中有文件丢失,可以用方法2,方法3去获取
./extract-files.sh
###2.从github项目地址:https://github.com/TheMuppets获取
只需要将对应你机型的厂商vendor的代码添加到LineageOS/.repo/local_manifests/roomservice.xml文件中就行了
<project name="TheMuppets/proprietary_vendor_xiaomi" path="vendor/xiaomi" remote="github" revision="lineage-16.0" />
###3.从rom中获取
参考官网教程 https://wiki.lineageos.org/extracting_blobs_from_zips.html
开始编译
配置变量
export USE_CCACHE=1
//配置缓存
ccache -M 50G
export CCACHE_COMPRESS=1
//开启自带的 Root 权限
export WITH_SU=true
//配置jack避免内存不足
export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx8G"
//去除所有本地化的设置,让命令能正确执行,bash 执行
export LC_ALL=C
//自定义编译输出路径,可选
export OUT_DIR=~/android/out
export USE_CCACHE=1;ccache -M 50G;export CCACHE_COMPRESS=1;export WITH_SU=true;export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx8G";export LC_ALL=C
编译
- 每次编译都要依次执行下面3局,不然就无法编译指定都机型
source build/envsetup.sh
croot
//默认是编译userdebug版本,如果编译发布版可以用 brunch lineage_lithium-user
brunch lithium
编译完成
编译完成之后只需要在命令行界面输入以下代码,就可以自动定位到生成的包的位置,当然,也可以手动cd到对应目录(~/LineageOS/out/target/product/'设备型号'/)。
cd $OUT
编译生成的文件名为lineage-‘日期’-16.0-‘设备代号’.zip以及对应的zip.md5sum,还有recovery.img。
到此,教程结束。
编译错误处理
//检查jack服务是否开启了
./prebuilts/sdk/tools/jack-admin list-server
//启动jack
prebuilts/sdk/tools/jack-admin start-server
如果出现不知道的错误,不妨 make update-api 说不定能找到错误的地方
某些机型编译失败处理技巧
- 对比 .repo/local_manifests/roomservice.xml 文件,检查相应文件夹是否clone下来了,
如果没有就手动去github上clone,然后复制进去,复制之前要确保正确checkout了相应版本 - 还要注意 kernel或者vendor中的机型中文件夹是不是空的
留言