編譯AOSP源碼 官方文檔寫的很詳細(xì)放典,Mac上有幾個坑需要注意下:(OS 10.14.5)
錯誤零區(qū)分大小寫的磁盤分區(qū)
官方文檔Creating a case-sensitive disk image也是有的,但是我感覺文檔放的稍微位置靠后,有時候會導(dǎo)致前面事情白做滋将。原因是Mac文件系統(tǒng)不區(qū)分大小寫,但是AOSP編譯要求區(qū)分大小寫江醇。
步驟:打開Disk Utility (磁盤工具)然后添加一個Volume救巷,記得選擇區(qū)分大小寫的選項就好了
錯誤一:找不到 JDK 的 tools.jar 包
build/core/config.mk:663: error: Error: could not find jdk tools.jar at /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/…/lib/tools.jar, please check if your JDK was installed correctly.
我首先 Java -v
看了下 JDK 確實是安裝了的,且包含在系統(tǒng)路徑下贬循,后來發(fā)現(xiàn)編譯時使用的環(huán)境變量并不是 “JAVA_HOME” 而是 “ANDROID_JAVA_HOME”咸包,解決方法很簡單,就是在~/.bash_profile 中添加
export ANDROID_JAVA_HOME=$JAVA_HOME
錯誤二:找不到對應(yīng)的 sdk 版本
FAILED: out/soong/build.ninja
out/soong/.bootstrap/bin/soong_build -t -l out/.module_paths/Android.bp.list -b out/soong -n out -d out/soong/build.ninja.d -o out/soong/build.ninja Android.bp
internal error: Could not find a supported mac sdk: [“10.10” “10.11” “10.12” “10.13”]
ninja: build stopped: subcommand failed.
運行命令查看本機安裝的 sdk 版本
find /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs -iname "*.sdk"
發(fā)現(xiàn)我本機安裝的版本是 10.14杖虾,確實不在配置文件的要求中烂瘫,最簡單粗暴的方法就是修改配置文件,在 /build/soong/cc/config/x86_darwin_host.go
的 darwinSupportedSdkVersions
變量中添加對應(yīng)的版本奇适。
事實證明坟比,這樣子做是不行的芦鳍,編譯之后出現(xiàn)了新的問題,就是 MacOSX10.14.sdk 版本導(dǎo)致的
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSUUID.h:26:49: error: nullability specifier ‘_Nullable’ cannot be applied to non-pointer type ‘uuid_t’ (aka ‘unsigned char [16]’)
(instancetype)initWithUUIDBytes:(const uuid_t _Nullable)bytes;
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSUUID.h:29:30: error: nullability specifier ‘_Nonnull’ cannot be applied to non-pointer type ‘uuid_t’ (aka ‘unsigned char [16]’)
(void)getUUIDBytes:(uuid_t _Nonnull)uuid;
(所以温算,這個故事告訴我們怜校,不要隨便亂改配置文件,別人沒有寫新的版本肯定是有原因的)
于是下載了一個低版本的 MacOSX.sdk注竿,解壓復(fù)制到 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
目錄下
注意下載文件是 .tar.xz
格式的茄茁,需要先用 xz -d
將 XXX.tar.xz 文件解壓成 XXX.tar 格式,然后用tar -xvf
解壓
錯誤三:Mac OS 版本過高導(dǎo)致 bison 有什么問題(我也不太清楚)
FAILED: out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.cpp
out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.h
BISON_PKGDATADIR=external/bison/data prebuilts/misc/darwin-x86/bison/bison -d --defines=out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.h -o out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.cpp system/tools/aidl/aidl_language_y.yy
[ 2% 1270/59686] cc out/soong/.intermediates/system/core/adf/libadf/libadf/android_arm_armv7-a_static_core/obj/system/core/adf/libadf/adf.o
ninja: build stopped: subcommand failed.
11:47:11 ninja failed with: exit status 1
make: *** [run_soong_ui] Error 1
解決辦法是安裝 bison 的補丁并重新編譯
首先進入 bison 的目錄巩割,并安裝補丁
cd /external/bison
git cherry-pick c0c852bd6fe462b148475476d9124fd740eba160
重新編譯
mm
這里 mm
命令如果執(zhí)行失效裙顽,則需退回根目錄重新執(zhí)行 source build/envsetup.sh
和 lunch XXX
,然后再回來執(zhí)行 mm
編譯成功后宣谈,替換 bison 目錄愈犹,然后重新編譯即可
cp /Volumes/Android/android-8.1.0_r1/out/host/darwin-x86/bin/bison /Volumes/Android/android-8.1.0_r1/prebuilts/misc/darwin-x86/bison/
錯誤四:內(nèi)存不夠了
GC overhead limit exceeded.
Try increasing heap size with java option ‘-Xmx’.
怎么操作都提示了,就是增加虛擬機的堆棧
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
修改后注意重啟下服務(wù)
./prebuilts/sdk/tools/jack-admin kill-server
./prebuilts/sdk/tools/jack-admin start-server
編譯完了之后闻丑,屏幕會出現(xiàn)這樣的畫面漩怎,就表示成功了(順便吐槽一句編譯完整個源碼目錄大概占了 128 GB 左右的磁盤空間,闊怕)
寫著寫著嗦嗡,發(fā)現(xiàn)了一篇文章寫的很好勋锤,防止鏈接過時,拷貝了內(nèi)容侥祭,附鏈接:
https://www.twblogs.net/a/5c9941bcbd9eee68b3b5abbd/zh-cn