前邊寫過aosp在Linux上(Ubuntu)的編譯文章,因為是在虛拟機裡邊,是以在友善的同時,效率也會有所折扣(調試編譯運作速度等)。是以在Mac上試驗了一次,發現友善很多。特此記錄下來。
大體流程還是與Android源代碼編譯筆記(支援5.x及以上版本) - Linux篇一緻的,細節地方有所不同。
安裝軟體包
JDK
這部分的要求對于各個平台是一緻的,具體參見安裝JDK
Command Line Tools
MacPorts
MacPorts是Mac平台的一個安裝包管理器。可以直接從其官網上下載下傳與你的Mac系統對應的安裝包。
Note: Make sure thatappears in your path before
/opt/local/bin
. If not, please add the following to your
/usr/bin
file:
~/.bash_profile
make, git, and GPG
$ POSIXLY_CORRECT= sudo port install gmake libsdl git gnupg
If using Mac OS X v10.4, also install bison:
$ POSIXLY_CORRECT= sudo port install bison
建立大小寫敏感的磁盤檔案
Mac預設情況下,雖然運作時是大小寫保護的,但是檔案系統本身确實大小寫不敏感的(你可以建立一個同名但大小寫不一樣的檔案或者檔案夾試試)。
為了避免
git
在執行中出現異常情況,是以需要另外建立一個大小寫敏感的磁盤檔案。我們之後的源代碼和編譯都在那裡邊進行。
我們使用sparse類型的檔案,它的優點在于後期可以根據需要調整大小。
指令如下:
$ hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size g ~/android.dmg
下載下傳好源碼編譯完之後隻剩下2g了,是以你可以考慮設定一個大一點的值。
This will create a
(or possibly a
.dmg
) file which, once mounted, acts as a drive with the required formatting for Android development.
.dmg.sparseimage
如果你想調整磁盤檔案大小,使用如下指令:
$ hdiutil resize -size <new-size-you-want>g ~/android.dmg.sparseimage
Helper方法
磁盤檔案建立出來之後,需要加載才可以使用。為了以後加載/解除安裝友善,我們可以在
~/.bash_profile
檔案中加入以下方法:
# mount the android file image
function mountAndroid { hdiutil attach ~/android.dmg -mountpoint /Volumes/android; }
# unmount the android file image
function umountAndroid() { hdiutil detach /Volumes/android; }
然後你就可以執行
mountAndroid
進行加載,
umoundAndroid
進行解除安裝了。非常友善。
注意将 attatch
後邊的磁盤檔案替換為你自己的檔案名。
可選配置
設定檔案描述符上限
Google是這麼說的
On Mac OS, the default limit on the number of simultaneous file descriptors open is too low and a highly parallel build process may exceed this limit.
To increase the cap, add the following lines to your
:
~/.bash_profile
# set the number of open files to be
ulimit -S -n
但是在實際當中,我并沒有配置這一項,也是編譯成功的。
緩存設定
具體參見設定ccache緩存 - 可選
在Mac平台下,需要執行Mac平台下的
ccache
指令,具體如下
$ prebuilts/misc/darwin-x86/ccache/ccache -M G
代碼下載下傳與編譯
參考Android源代碼編譯筆記(支援5.x及以上版本) - Linux篇。
這部分内容是一模一樣的。我編譯了master分支,耗時約1.75小時。
參考
- Android源代碼編譯筆記(支援5.x及以上版本) - Linux篇
- Setting up a Mac OS build environment