基礎(chǔ)環(huán)境
主機(jī): windows 10
虛機(jī): ubuntu 20.04 LTS (4 C 12G M 300G D)
手機(jī): Mi 10 Lite 5G / Redmi K40
注
虛機(jī)配置有點(diǎn)高,否者會(huì)編譯的非常慢偏友,硬盤和內(nèi)存不足導(dǎo)致失敗了很多次,最后將 硬盤更新到 300G 之后編譯成功????
環(huán)境安裝
# 安裝基礎(chǔ)庫(kù)
sudo apt install -y bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5 libncurses-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev
# 安裝其他依賴庫(kù)
sudo apt install -y imagemagick libbz2-dev libssl-dev lzma ncftp bash-completion
# 安裝 python
sudo apt install -y python
代碼同步
基于清華源同步全量 LineageOS
代碼
- 配置
repo
# 下載 repo
mkdir ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
# 配置環(huán)境變量
cat >> ~/.bashrc <<_EOF
# set PATH so it includes user's private bin if it exists
if [ -d "\$HOME/bin" ] ; then
PATH="\$HOME/bin:\$PATH"
fi
_EOF
# 使能環(huán)境變量
source ~/.bashrc
- 初始化
git / repo
版本信息
# 創(chuàng)建工作目錄
mkdir -p lineageos
cd lineageos
# 查看版本
git --git-dir=.repo/manifests/.git/ branch -a
# 初始化版本
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b lineage-19.1
- 修改
repo
同步地址
修改 .repo/manifests/default.xml
文件
<!-- 添加 tuna 源 -->
- <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" />
<!-- 修改 aosp 源地址 -->
- <remote name="aosp"
- fetch="https://android.googlesource.com"
+ <remote name="aosp"
+ fetch="https://mirrors.tuna.tsinghua.edu.cn/git/AOSP"
<!-- 修改默認(rèn) git 地址 -->
- <default revision="..."
- remote="github"
+ remote="lineage"
- 同步代碼
repo sync -j4 -c --no-clone-bundle
注
再次同步時(shí)使用 repo sync --no-clone-bundle
編譯
- 添加
ccache
支持
注
添加緩存加速編譯的作用, 可以使用 ccache -o compression=true
命令來(lái)壓縮 ccache
echo export USE_CCACHE=1 >> ~/.bashrc
prebuilts/misc/linux-x86/ccache/ccache -M 50G
- 選擇設(shè)備
source build/envsetup.sh
# 小米 Redmi K40
breakfast alioth
# 小米 Mi 10 Lite 5G
breakfast monet
# 鏈接手機(jī)到 ubuntu 系統(tǒng)
./extract-files.sh
注
先安裝 adb
和 fastboot
工具, 下載 Google工具包
# 下載工具包
wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
# 解壓工具包
unzip platform-tools-latest-linux.zip -d ~
# 配置環(huán)境變量
cat >> ~/.profile <<_EOF
if [ -d "$HOME/platform-tools" ] ; then
PATH="$HOME/platform-tools:$PATH"
fi
_EOF
# 使能變量
source ~/.profile
注
也同樣可以從線刷包中提取相關(guān)的文件,具體操作如下:
# 創(chuàng)建基礎(chǔ)目錄
mkdir /srv/workspace/alioth-signed
# 下載
wget https://mirrors.tuna.tsinghua.edu.cn/lineage-rom/full/alioth/20220730/lineage-19.1-20220730-nightly-alioth-signed.zip
# 解壓包
unzip path/to/lineage-*.zip
# 解包
payload_dumper payload.bin
# mount system 鏡像
mkdir system/
sudo mount system.img system/
# 從 system 鏡像中抽取必要內(nèi)容
./extract-files.sh /srv/workspace/alioth-signed
注
安裝 payload_dumper
工具包
# 安裝 payload_dumper 工具包
pip install --user payload_dumper
或
git clone https://github.com/vm03/payload_dumper
# 解包
payload_dumper payload.bin
# 解部分內(nèi)容
payload_dumper --partitions boot,dtbo,vendor payload.bin
# 打 patch 包
payload_dumper --diff payload.bin
- 多線程編譯
croot
# 編譯 Redmi K40
brunch alioth
# 編譯 Mi 10 Lite 5G
brunch monet
注
在 cd $OUT
進(jìn)入到 $OUT
目錄下存在 lineage-19.1-20220804-UNOFFICIAL-alioth.zip
注
執(zhí)行 brunch
命令時(shí)會(huì)自動(dòng)先執(zhí)行 breakfast
命令享怀,因此可以直接執(zhí)行 brunch
命令
注
breakfast
命令實(shí)際會(huì)同步 linux
內(nèi)核代碼等邏輯,此處主要是在 local_manifest.xml
中進(jìn)行配置的趟咆,因此同樣需要將其配置改為 清華源
即可快速同步下來(lái)
注
參考 lineageOS 源代碼鏡像使用幫助