现在编译rom的中文教程,说实话,对新手友好的真的很少。如果你对编译rom有兴趣,那么这篇文章一定可以帮到你,它会帮助你少走很多弯路。


安装依赖

这里以ubuntu为例

sudo apt-get update && sudo apt-get install git-core gnupg flex bison gperf libsdl1.2-dev libesd0-dev libwxgtk3.0-dev squashfs-tools build-essential zip curl libncurses5-dev zlib1g-dev openjdk-8-jre openjdk-8-jdk pngcrush schedtool libxml2 libxml2-utils xsltproc lzop libc6-dev schedtool g++-multilib lib32z1-dev lib32ncurses5-dev gcc-multilib maven tmux screen w3m ncftp liblz4-tool pngquant rsync openjdk-8-jdk

设置repo

 mkdir ~/bin
 PATH=~/bin:$PATH

使用Git Repo 镜像

curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo

repo的运行过程中会尝试访问官方的git源更新自己,如果想使用tuna的镜像源进行更新,可以将如下内容复制到你的~/.bashrc里

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

建立你的rom编译目录以及同步代码

目录的名称随意,不过建议使用和rom名称相近的目录名

mkdir ~/rr && cd ~/rr

每个rom的源都是不一样的,请参考你所要编译的rom的帮助文档,这里以rr为例

repo init -u https://github.com/ResurrectionRemix/platform_manifest.git -b oreo

使用清华源代码镜像 打开.repo/manifest.xml,将

  <remote  name="aosp"
       fetch="https://android.googlesource.com"

改成

  <remote  name="aosp"
       fetch="https://aosp.tuna.tsinghua.edu.cn"

开始同步

repo sync -f --force-sync --no-clone-bundle

rr同步的代码大概有26GB左右,如果你的网速较慢,可能会同步失败,如果失败就再次执行 repo sync -f --force-sync

把适合你机型的device vendor kernel,放到对应的目录(device vendor kernel你可以向你的rom开发者索要或者自己去github寻找)

示例路径

 ~/rr/device/xiaomi/santoni
~/rr/vendor/xiaomi/santoni
~/rr/kernel/xiaomi/msm8937

有些开发者device只有lineage的tree,当编译某些rom时需要做一些修改。rr的话可以参考我的提交

rr

santoni: remap buttons

修改JACK默认使用的内存大小

export ANDROID_JACK_VM_ARGS="-Xmx4g -Dfile.encoding=UTF-8 -XX:+TieredCompilation"

如果编译出错,执行下面的命令,然后继续编译

 out/host/linux-x86/bin/jack-admin kill-server
 out/host/linux-x86/bin/jack-admin start-server

可选项(根据你的需要,决定是否使用这些变量)

设定缓存加快编译

export USE_CCACHE=1
prebuilts/misc/linux-x86/ccache/ccache -M 50G

开启root(仅在基于los的rom上适用)

export WITH_SU=true

禁用ninja

export USE_NINJA=false

开始编译

 . build/envsetup.sh
brunch santoni

santoni是我的手机的代号,搞成你自己的手机代号 编译完成的话,它会告诉你刷机包的存放位置

本文参考以下文章

https://mirrors.tuna.tsinghua.edu.cn/help/lineageOS/

https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/

记录下编译LineageOS的过程

https://github.com/ResurrectionRemix/platform_manifest