編譯android源代碼(aosp)

 

 
步驟1:按照官方的 文檔,下載源碼,配置環境,並執行相應的命令。最好按照官方的硬件和系統配置build。
 
build的版本是6.0,源碼目錄是/home/koder/android-source-20151229
 
Requirements:
  • 下載的源碼很大,估計有30,40G左右。加上build,最好騰出100+的空間來。
  • 按官方說的MAC OS或者Ubuntu LTS (14.04)X64,本身是Ubuntu LTS (14.04) 64位。
  • 硬件問題:內存不足,看文末問題1。
 
 
 
有一個注意文檔說的:lunch aosp_arm-eng
這裏是要build出一個適應於emulator的img,而且容許debug。
 
aosp_arm-eng 表示target或者 build configuration, 格式是:  BUILD-BUILDTYPE
 
aosp_arm是BUILD。若是但願build不一樣設備或者emulator的img,就要不一樣的值。 點擊這裏有介紹。其中arm是叫作code name
 
eng是BUILDTYPE:
Buildtype Use
user limited access; suited for production
userdebug like "user" but with root access and debuggability; preferred for debugging
eng development configuration with additional debugging tools

target有的例子有這些:
Device Code name Build configuration
Nexus 6P angler aosp_angler-userdebug
Nexus 5X bullhead aosp_bullhead-userdebug
Nexus 6 shamu aosp_shamu-userdebug
Nexus Player fugu aosp_fugu-userdebug
Nexus 9 volantis (flounder) aosp_flounder-userdebug
Nexus 5 (GSM/LTE) hammerhead aosp_hammerhead-userdebug
Nexus 7 (Wi-Fi) razor (flo) aosp_flo-userdebug
Nexus 7 (Mobile) razorg (deb) aosp_deb-userdebug
Nexus 10 mantaray (manta) full_manta-userdebug
Nexus 4 occam (mako) full_mako-userdebug
Nexus 7 (Wi-Fi) nakasi (grouper) full_grouper-userdebug
Nexus 7 (Mobile) nakasig (tilapia) full_tilapia-userdebug
Galaxy Nexus (GSM/HSPA+) yakju (maguro) full_maguro-userdebug
Galaxy Nexus (Verizon) mysid (toro) aosp_toro-userdebug
Galaxy Nexus (Experimental) mysidspr (toroplus) aosp_toroplus-userdebug
PandaBoard (Archived) panda aosp_panda-userdebug
Motorola Xoom (U.S. Wi-Fi) wingray full_wingray-userdebug
Nexus S soju (crespo) full_crespo-userdebug
Nexus S 4G sojus (crespo4g) full_crespo4g-userdebug

Do not use 4.1.1 on a Nexus 7 that was originally sold with 4.1.2 or newer.html

 

步驟2:順利make成功後。
 
會在目錄/home/koder/android-source-20151229/out/target/product/generic下生成系統系統的文件,包括system.img, ramdisk.img,userdata.img等。
 
而後運行,因爲build的是emulator的img,因此就運行虛擬機。
官方文檔說,會自動把環境變量設置好,可是執行emulator的時候,發現並無該命令,因此須要本身找到emulator的目錄。emulator在prebuilts/android-emulator下,prebuilts目錄是官方提供的,下載源碼時就已經build好的一些工具和庫,包括kernel也在這下面,因此若是本身要build kernel,就看 這裏。題外話了,回到emulator,切換到emulator目錄,運行:
./emulator \
-sysdir ${ANDROID_PRODUCT_OUT} \
-system ${ANDROID_PRODUCT_OUT}/system.img \
-ramdisk ${ANDROID_PRODUCT_OUT}/ramdisk.img \
-data ${ANDROID_PRODUCT_OUT}/userdata.img \
-kernel /home/koder/android-source-20151229/prebuilts/qemu-kernel/arm/kernel-qemu-armv7 \
-skindir /home/koder/android-source-20151229/sdk/emulator/skins \
-memory 2048 \
-partition-size 2048 \
-skin WVGA800 \
-scale 0.7
 
本身改好對應目錄就行了。我的環境變量是:
 
JAVA_HOME=/home/koder/Documents/jdk1.8.0_65
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ANDROID_HOME=/home/koder/Documents/android-sdk-linux
ANDROID_BUILD_OUT_HOST=/home/koder/android-source-20151229/out/host/linux-x86/bin
ANDROID_PRODUCT_OUT=/home/koder/android-source-20151229/out/target/product/generic
PATH=$ANDROID_HOME:$ANDROID_BUILD_OUT_HOST:$PATH
export JAVA_HOME PATH CLASSPATH ANDROID_PRODUCT_OUT
 
           到這裏就OK了。
 
 
BUILD過程當中遇到的問題:
 
1. 提示:increasing heap size。就是Java虛擬機的heap size不夠了,添加環境變量:
export _JAVA_OPTIONS=-Xmx8192m
賦值大小看本身機器了。
然而,即便這樣設置了,有時候也不起做用,由於可能機器自己硬件內存就不足了,根本就沒有8G那麼多好嗎。因爲本身的機器是8G的,並且運行在虛擬機上,只分配到4G的空間,因此build的過程當中,內存不足的問題卡了本身好久好久,並且官方說,最好是有16g ram以上,幾乎要放棄了。最後想了個辦法,增長swap內存。
至於如何增長swap內存,參考這裏
 
本身直接swap增長了16G,因爲原本是8G,因此最好是24G了。
感嘆一下,UNIX的「Everything is file」的偉大,硬件不夠,軟件來補,呵呵~~~
解決這個內存問題後,就順利的build出來了。
 
 

另外:linux

1.查看cccache:watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s
相關文章
相關標籤/搜索