下載準備
硬件要求
至少分割出100G到150G以上的硬盤空間,并設置類型為『區分大小寫,可讀寫』類型
軟件要求
1、Xcode 4.5.2版本及其以上,以及對應的Command Line Tools,一定要相互對應,并且最好從官網下載,否則后面編譯的時候會出問題。我下載的是7.3.1版本。
2、JDK 1.8_45
3、python 2.7
4、git 1.7
5、更新gnu-make命令到3.8.2版本
6、從https://developers.google.com/android/nexus/blobs-preview處下載創建虛擬機類型對應的二進制文件,例如,我創建的虛擬機是Nexus 6P類型的,我需要下載對應的硬件二進制文件
下載源碼
1、在外掛硬盤上創建android分區,目錄/Volumes/android
2、下載repo工具
1)mkdir ~/bin
2)PATH=~/bin:$PATH
3)可以通過下載工具下載repo,下載地址:
https://storage.googleapis.com/git-repo-downloads/repo
之后,將下載的repo粘貼到~/bin目錄下
4)chmod a+x ~/bin/repo
3、下載最新的初始化包,使用清華大學的鏡像資源
可以通過下載工具從地址
https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar下載。并通過解壓工具解壓即可。
4、檢出代碼
1)修改repo的配置
編輯~/bin/repo,把REPO_URL一行替換成下面的:
REPO_URL = 'https://gerrit-google.tuna.tsinghua.edu.cn/git-repo'
2)repo sync –f
編譯源碼
1、跳轉到/Volumes/android/aosp目錄
2、$ source build/envsetup.sh
3、執行lunch命令,并根據虛擬機的類型來選擇lunch的參數,我的虛擬機是X86類型,我選擇的是aosp_x86_64-eng
4、make –j4
出現這一行表示編譯成功。
編譯過程中出現的錯誤
1、Unsupported curl, please use a curl not based on SecureTransport
安裝curl
brew install curl --with-openssl
exportPATH=$(brew --prefixcurl)/bin:$PATH
參考鏈接:
http://stackoverflow.com/questions/33318756/while-i-make-the-source-of-android-6-0-it-failed
2、Jack“Out of memory error”
1)在當前工作目錄下(/Volumes/android/aosp),找到修改Jack的配置文件prebuilts/sdk/tools/jack-admin,在其中找到start-server函數,直接修改其啟動參數,添加-Xmx參數
更改為
其中『-Xmx4096m』是添加的部分
2)之后刪除$HOME/.jack-server文件夾及其文件夾下的內容,這里是之前啟動jack-server是創建的內容
cd $HOME
sudo rm -r -f .jack-server
3)重新開始編譯
3、stat: cannot read file system information for ‘%z’: No such file ordirectory
誤裝了coreutils
卸載:brew uninstall coreutils
參考連接:
http://stackoverflow.com/questions/28784392/building-aosp-on-mac-yosemite-and-xcode
啟動模擬器
$emulator
注意,模擬器和編譯版本中,選擇的lunch選項一定要相互對應,否則模擬器將一直黑屏,無法啟動。
最終運行成功結果
參考文檔:
1、https://source.android.com/source/requirements.html#software-requirements官方文檔
2、https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/清華大學AOSP鏡像源
3、https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/gnu安裝教程文檔
4、http://www.lxweimin.com/p/98e6a6d608e0Mac OX編譯aosp參考文檔