我的環境
Ubuntu 18.04.5 LTS
清華源
https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
安裝repo, 3種方式
# 1. 無需安裝, 下載初始化包中自帶最好用
# 2. ubuntu apt-get
sudo apt-get install repo
# 3. 單獨腳本的方式(不推薦, 至少在我的電腦上, 會報一些python腳本兼容性錯誤, 手動改了又會遇到uncommit change錯誤)
mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo
使用每月更新的初始化包
# 下載初始化包, 查看包列表 https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/, 由於最新包太大了, 我只需要Android-8.0的包
wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-20190101.tar
# 或下載最新包8-90G吧 wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 解壓得到的 AOSP 工程目錄 tar xf aosp-latest.tar cd AOSP # 這時 ls 的話什么也看不到,因為只有一個隱藏的 .repo 目錄
# 正常同步一下,即可得到完整目錄 repo sync # 或 repo sync -l 僅checkout代碼(這種方式比較快,不會fetch最新的遠程倉庫,也就是如果我下載的是20190101.tar,則最新的修改就到這天,之后至今天的修改,不同步.)
# 如果不加 -l 選項, 則更新本地倉庫為最新上百G了.
查看分支列表
# 進入Repo目錄,查看所有分支 cd .repo/manifests git branch -a
# 如果像我一樣使用repo sync -l選項同步, 會發現分支最新只到android-9.0
切換到需要的目標分支
查看 https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds 找到你想使用的分支, 這里我選擇 android-8.1.0_r35 , 原諒我手上只有一台Pixel 2. 所以要選擇支持我這台設備的分支, 為后續刷機作准備
# 切換分支 repo init -b android-8.1.0_r35
如果提示無法連接到 gerrit.googlesource.com,請參照git-repo的幫助頁面的更新一節。
環境配置
sudo apt-get update sudo apt-get install openjdk-8-jdk
# 安裝必要程序包 (我就不裝)
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip
編譯
source build/envsetup.sh
lunch aosp_arm64-eng
# 若想查看所有lunch選項, 可以輸入lunch 回車
我們先編譯一個模擬器版的, 因為AOSP缺少vendor目錄, 即不包含實體設備的驅動
輸入2 回車, 接下來
make -j8 # 我的電腦是4核8線程的, 一次全編 它可以從早編到晚 ~~
不出意外會編譯成功. 看下輸出目錄, 會有各種img
ls $OUT
編譯完成后可以運行模擬器看下效果
emulator
關於lunch構建目標
構建類型 | 說明 |
user | 權限受限;適用於生產環境 |
userdebug | 與“user”類似,但具有 root 權限和調試功能;是進行調試時的首選編譯類型 |
eng | 具有額外調試工具的開發配置, 會關閉用於提供良好用戶體驗的各種優化 |
有意外發生 ~
遇到的錯誤
# 報python語法錯誤
acer@acer-TravelMate-P249-G3-MG:~/aosp-test/aosp$ repo sync -l Traceback (most recent call last): File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 198, in GetBranch b = self._branches[name] KeyError: 'default' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/acer/aosp-test/aosp/.repo/repo/main.py", line 531, in <module> _Main(sys.argv[1:]) File "/home/acer/aosp-test/aosp/.repo/repo/main.py", line 507, in _Main result = repo._Run(argv) or 0 File "/home/acer/aosp-test/aosp/.repo/repo/main.py", line 158, in _Run copts, cargs = cmd.OptionParser.parse_args(argv) File "/home/acer/aosp-test/aosp/.repo/repo/command.py", line 67, in OptionParser self._Options(self._optparse) File "/home/acer/aosp-test/aosp/.repo/repo/subcmds/sync.py", line 189, in _Options self.jobs = self.manifest.default.sync_j File "/home/acer/aosp-test/aosp/.repo/repo/manifest_xml.py", line 360, in default self._Load() File "/home/acer/aosp-test/aosp/.repo/repo/manifest_xml.py", line 400, in _Load b = m.GetBranch(m.CurrentBranch).merge File "/home/acer/aosp-test/aosp/.repo/repo/project.py", line 814, in GetBranch return self.config.GetBranch(name) File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 200, in GetBranch b = Branch(self, name) File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 725, in __init__ self.merge = self._Get('merge') File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 768, in _Get return self._config.GetString(key, all_keys = all_keys) File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 131, in GetString v = self._cache[_key(name)] File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 248, in _cache self._cache_dict = self._Read() File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 254, in _Read d = self._ReadGit() File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 299, in _ReadGit for line in d.decode('utf-8').rstrip('\0').split('\0'): # pylint: disable=W1401 AttributeError: 'str' object has no attribute 'decode'
解決辦法: 試試用 .repo/repo/repo sync -l
# 遇到錯誤 [490/999] including ./hardware/qcom/keymaster/Android.mk ... [491/999] including ./hardware/qcom/media/Android.mk ... hardware/qcom/media/msm8998/mm-video-v4l2/vidc/venc/Android.mk:60: warning: "venc: PQ compiled out" [492/999] including ./hardware/qcom/msm8998/Android.mk ... including hardware/qcom/msm8998/gpt-utils/Android.mk ... including hardware/qcom/msm8998/json-c/Android.mk ... including hardware/qcom/msm8998/thermal-engine/Android.mk ... including hardware/qcom/msm8998/time-services/Android.mk ... [493/999] including ./hardware/qcom/power/Android.mk ... [494/999] including ./hardware/qcom/sdm845/Android.mk ... ./hardware/qcom/power/Android.mk:3: error: ./hardware/qcom/sdm845/Android.mk: No such file or directory 15:33:38 ckati failed with: exit status 1
解決: 進入hardware/qcom/sdm845, ls -l 可見一些無效的符號鏈接, 直接刪除即可
參考:
https://source.android.com/source/initializing
https://source.android.com/setup/build