0. 環境準備
-
Ubuntu 16.04 LTS(預留至少95GB磁盤空間,實測占94.2GB)
-
Pixel 2 XL
要買歐版的,不要美版的。
歐版能解鎖BootLoader、能刷機。
美版IMEI里一般帶“v”或者"version",這樣不能解鎖BootLoader、也不能刷機。 -
想刷入Android-8.1.0_r1
1. 下載源碼
參考:https://blog.csdn.net/aichu6610/article/details/116071003
注意改用 python3 ~/bin/repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r1
1.1 安裝并配置git和repo
安裝git
sudo apt install git
git config --global user.name “your name”
git config --global user.email “XXX@XXX.com”
安裝并配置repo
sudo apt install curlmkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
安裝JDK 8
sudo apt update
sudo apt install openjdk-8-jdk
創建文件目錄
mkdir /home/tom/Android-8.1.0_r1
cd /home/tom/Android-8.1.0_r1
修改配置
找到~/bin/repo文件,修改如下配置
REPO_URL = ‘https://mirrors.tuna.tsinghua.edu.cn/git/git-repo’
在終端下運行
git config --global url.https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/.insteadof https://android.googlesource.com
執行gedit ~/.bashrc
然后在末尾添加:
export PATH=~/bin:$PATH
export REPO_URL=‘https://mirrors.tuna.tsinghua.edu.cn/git/git-repo’
運行 source ~/.bashrc
使環境變量生效
1.2 使用repo同步代碼
Repo是谷歌提供的一套python腳本,封裝了一系列git命令,用來管理多個git庫
初始化repo倉庫
python3 ~/bin/repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r1
如果想用其他版本,在這里查詢:
https://source.android.com/source/build-numbers?hl=zh-cn
同步代碼
repo sync -j8
這個過程會持續數個小時
-j8貌似是并行的意思,如果報錯可以去掉-j8試試
中間有報錯,但不知道是否有影響
某些時刻輸出過長,所以最后就多出來一截 應該無大礙
以防萬一,又 repo sync 了幾遍
2. 準備驅動腳本
地址:https://developers.google.com/android/drivers
要找 android-8.1.0_r1 的 pixel 2xl的驅動
android-8.1.0_r1就是OPM1.171019.011
參考:https://source.android.com/docs/setup/about/build-numbers?hl=zh-cn#source-code-tags-and-builds
所以鎖定:
https://developers.google.com/android/drivers#taimenopm1.171019.011
將上面兩個link的內容下載下來,得到兩個sh:
extract-google_devices-taimen.sh
extract-qcom-taimen.sh
3. 編譯
3.1 編譯
source build/envsetup.sh
將下載的兩個驅動腳本 放入源碼根目錄下 并執行
./extract-google_devices-taimen.sh
./extract-qcom-taimen.sh
一頓敲回車(注意不要敲過油了)
最后敲入I ACCEPT
執行lunch
lunch
我的是Pixel 2 XL,也就是 taimen,所以選27
(各機型的對照參考:https://blog.csdn.net/guyongqiangx/article/details/123971895)
執行 time make
(這里不并行了,并行容易出bug,如果想并行可以time make -j4
)
time make
3.2 報錯:Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))’ failed.
[ 4% 5148/105788] Lex: applypatch <= bootable/recovery/edify/lexer.ll
FAILED: out/target/product/taimen/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp
/bin/bash -c "prebuilts/misc/linux-x86/flex/flex-2.5.39 -oout/target/product/taimen/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp bootable/recovery/edify/lexer.ll"
flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
Aborted (core dumped)
[ 4% 5153/105788] target arm C++: libaudioprocessing_32 <= frameworks/av/media/libaudioprocessing/AudioResamplerDyn.cpp
ninja: build stopped: subcommand failed.
15:07:08 ninja failed with: exit status 1
解決辦法:參考:https://groups.google.com/g/android-building/c/0kzPnw3akxg/m/ozJe-XlSAQAJ
export LC_ALL=C
然后
make clean
time make
出現了新的報錯
3.3 報錯:Out of memory error GC overhead limit exceeded.
[ 62% 65895/105788] Building with Jack: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex
FAILED: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex
/bin/bash out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex.rsp
Out of memory error (version 1.3-rc7 'Douarn' (445000 d7be3910514558d6715ce455ce0861ae2f56925a by android-jack-team@google.com)).
GC overhead limit exceeded.
Try increasing heap size with java option '-Xmx<size>'.
Warning: This may have produced partial or corrupted output.
[ 62% 65900/105788] //art/compiler:libart-compiler clang++ optimizing/optimizing_compiler.cc [linux]
ninja: build stopped: subcommand failed.
20:28:27 ninja failed with: exit status 1
解決辦法:參考 https://blog.csdn.net/liangtianmeng/article/details/86665237
在文件/prebuilts/sdk/tools/jack-admin中修正-Xmx參數
修改變量JACK_SERVER_VM_ARGUMENTS,添加參數 -Xmx2048M
JACK_SERVER_VM_ARGUMENTS="${JACK_SERVER_VM_ARGUMENTS:=-Dfile.encoding=UTF-8 -XX:+TieredCompilation -mx2048M}"
然后
make clean
time make
至此,編譯成功了
4. 刷機
4.1 Ubuntu安裝fastboot和adb
在Ubuntu系統上安裝ADB Fastboot
sudo apt install android-tools-adb
sudo apt install android-tools-fastboot
4.2 手機OEM解鎖
要買歐版的,不要美版的。
歐版能解鎖BootLoader、能刷機。
美版IMEI里一般帶“v”或者"version",這樣不能解鎖BootLoader、也不能刷機。
手機解鎖
參考:https://www.cnblogs.com/ciml/p/13949911.html
adb reboot bootloader
# 先看看設備是否連接成功
fastboot devices
# 解鎖 (用于2015年及之后的設備)
fastboot flashing unlock# 老設備解鎖 (2014及以前的設備)
fastboot oem unlock
這里用fastboot flashing unlock
如果報錯
FAILED (remote: 'Flashing Unlock is not allowed')
fastboot: error: Command failed
說明手機的開發者模式里“OEM解鎖”沒有打開
需要保證網絡暢通,確保能訪問Google
再次adb reboot bootloader
手機進入bootloader
adb reboot bootloader
fastboot flashing unlock
之后通過音量加減鍵選中Yes,通過電源鍵確認
4.3 刷入img鏡像
參考:https://www.cnblogs.com/ciml/p/13714036.html
在剛才編譯源碼的同一終端窗口內執行
fastboot flashall
如果報錯 error: ANDROID_PRODUCT_OUT not set
大概率是沒在同一終端窗口執行
解決方法:執行
export ANDROID_PRODUCT_OUT=~/Android-8.1.0_r1/out/target/product/taimen
其中,~/Android-8.1.0_r1/out/target/product/taimen
是img文件所在的目錄
再次執行fastboot flashall
成功!