Mac 10.14 編譯Android 8.1源碼及刷入nexus 6p

環境準備

官網 描述得已經至關清楚了 ,這裏稍微總結一下:php

建立區分大小寫的磁盤映像

mac系統默認是不區分大小寫的,因此咱們須要建立一個區分大小寫的文件系統html

hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 60g ~/android.dmg 
複製代碼

這將建立一個.dmg.sparseimage文件,該文件在裝載後可用做具備 Android 開發所需格式的驅動盤。java

按官網所說完成編譯至少須要 25GB 空間,相信我,其實至少須要60G。固然,空間大小後面還能夠經過如下命令修改linux

hdiutil resize -size <new-size-you-want>g ~/android.dmg.sparseimage
複製代碼

爲了方便,咱們還能夠往環境變量配置文件(~/.bash_profile--bash,~/.zshrc--zsh)添加輔助函數android

  • 裝載函數
# mount the android file image
mountAndroid() { hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android; 
複製代碼
  • 卸載函數
 # unmount the android file image
umountAndroid() { hdiutil detach /Volumes/android; }
複製代碼

安裝所需的軟件

  • JDKc++

    各類 Android 版本使用的 Java 版本不同,請參閱相關要求git

    我這裏是編譯Android8.1.0 ,因此使用java1.8shell

  • Xcode 命令行工具bootstrap

xcode-select --install
複製代碼
  • MacPortsapi

    macports.org 下載安裝,請確保 /opt/local/bin 在路徑中顯示在 /usr/bin 前面。不然,請將如下內容添加到環境變量配置文件(~/.bash_profile--bash,~/.zshrc--zsh)中:

export PATH=/opt/local/bin:$PATH
複製代碼

經過 MacPorts 獲取 Make、Git 、 GPG、BISON 軟件包

POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg bison
複製代碼

設置文件描述符數量上限

在 Mac OS 中,可同時打開的文件描述符的默認數量上限過低,在高度並行的編譯流程中,可能會超出此上限。要提升此上限,請將下列行添加到環境變量配置文件(~/.bash_profile--bash,~/.zshrc--zsh)中:

# set the number of open files to be 1024
ulimit -S -n 1024
複製代碼

下載源代碼

Android 源代碼樹位於由 Google 託管的 Git 代碼庫中。爲了在 Android 環境中更輕鬆地使用 Git,Google開發了Repo

安裝 Repo

  1. 確保主目錄下有一個 bin/ 目錄,而且該目錄包含在路徑中:
mkdir ~/bin
PATH=~/bin:$PATH
複製代碼
  1. 下載 Repo 工具,並確保它可執行
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
複製代碼

repo 初始化

進入咱們一開始建立的文件系統,建立一個空目錄

➜  ~ mountAndroid
/dev/disk3          	GUID_partition_scheme
/dev/disk3s1        	EFI
/dev/disk3s2        	Apple_HFS                      	/Volumes/android
➜  ~ cd /Volumes/android
➜  ~ mkdir aosp
➜  ~ cd aosp
複製代碼

指定須要checkout對應的源代碼標記和編譯版本

repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r50
複製代碼

初始化成功後,目錄中應包含一個 .repo 目錄。

下載

這時候就能夠開始漫長的下載過程了

repo sync
複製代碼

同步操做順利的話將須要 1 個小時或更長時間完成,

下載驅動

官網下載對應機型驅動便可,下載完成後解壓,依次執行裏面的sh文件,如:

$ ./extract-huawei-angler.sh

The license for this software will now be displayed.
You must agree to this license before using this software.

Press Enter to view the licensels
複製代碼

執行完畢,驅動文件會釋放到vendor目錄。

編譯

清理

make clobber
複製代碼

設置環境

source build/envsetup.sh
複製代碼

選擇目標

➜  ~ lunch

You're building on Darwin

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. aosp_deb-userdebug
     8. aosp_flo-userdebug
     9. full_fugu-userdebug
     10. aosp_fugu-userdebug
     11. mini_emulator_arm64-userdebug
     12. m_e_arm-userdebug
     13. mini_emulator_mips-userdebug
     14. mini_emulator_x86-userdebug
     15. mini_emulator_x86_64-userdebug
     16. aosp_flounder-userdebug
     17. aosp_angler-userdebug
     18. aosp_bullhead-userdebug
     19. aosp_hammerhead-userdebug
     20. aosp_hammerhead_fp-userdebug
     21. aosp_shamu-userdebug
     22. aosp_bullhead-userdebug
     23. aosp_angler-userdebug
複製代碼

由於我要編譯nexus6p,這裏選擇23,其餘設備能夠參考選擇設備編譯系統

編譯代碼

make -j8
複製代碼

-jN 表示編譯並行任務數,這個示電腦狀況而定,通常取cpu數的1~2倍就能夠

編譯遇到問題

找不到對應的macOS.sdk

  • 報錯日誌
[44/44] bootstrap out/soong/.minibootstrap/build.ninja.in 
[4/4] out/soong/.bootstrap/bin/minibp out/soong/.bootstrap/build.ninja 
[860/861] glob vendor///Android.bp 
[54/54] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja 
FAILED: out/soong/build.ninja 
out/soong/.bootstrap/bin/soong_build -t -b out/soong -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"] 
ninja: build stopped: subcommand failed. 
17:53:06 soong failed with: exit status 1

複製代碼
  • 解決方法

    修改/build/soong/cc/config/x86_darwin_host.go文件,添加10.14支持,以下

darwinSupportedSdkVersions = []string{
"10.10",
"10.11",
"10.12",
"10.14", // 添加mac sdk 10.14
}
複製代碼

遇到bison 錯誤

  • 報錯日誌
FAILED: out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.c out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.h 
BISON_PKGDATADIR=external/bison/data prebuilts/misc/darwin-x86/bison/bison -d --defines=out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.h -o out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.c external/selinux/checkpolicy/policy_parse.y 
[ 0% 309/87784] //external/libcxx:libc++_static header-abi-dumper src/random.cpp [arm] 
ninja: build stopped: subcommand failed. 
18:05:05 ninja failed with: exit status 1 

複製代碼
  • 解決辦法
cd /Volumes/AOSP/external/bison
git cherry-pick c0c852bd6fe462b148475476d9124fd740eba160
mm 
# 用新生成的bison替換掉原bison文件
cp /Volumes/AOSP/out/host/darwin-x86/bin/bison /Volumes/AOSP/prebuilts/misc/darwin-x86/bison/ 
# 從新編譯
make -j8
複製代碼

刷機

通過漫長的等待和反覆折騰後,終於到了最後一步---刷機。

# 手機鏈接電腦狀況下
adb reboot bootloader 
# 進入源碼編譯輸出的目錄 
fastboot flashing unlock 
fastboot flashall -w 

複製代碼

Done

參考連接

source.android.com/setup/build…

www.jianshu.com/p/1c3d47b20…

相關文章
相關標籤/搜索