ubuntu10.10編譯Android源碼

說明:
爲了方便下載Android 源碼, google提供了一個叫repo的腳本。android源碼分爲一百多個模塊,最新的froyo代碼到目前爲止,有158個模塊。採用這個腳本,可以分模塊的同步源碼。這個腳本除了可以下載源碼,還可以提交自己的代碼到google的服務器上,只要有權限。實際上,android的源代碼是使用 git 管理的,這個腳本里面主要就是對git命令的封裝。因此,我們需要把repo腳本下下來,然後運行。
1. 下載源碼 
mkdir android_src
cd android_src
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo >./repo
chmod a+x repo
打開https://android.googlesource.com/new-password打開,申請結果拷貝到~/.netrc
sudo ./repo init -u https://android.googlesource.com/a/platform/manifest -b android-2.2_r1
輸入用戶名和郵箱
-b 後面是分支,不寫-b參數默認master
 * [new branch]      android-1.6_r1
 * [new branch]      android-1.6_r1.1
 * [new branch]      android-1.6_r1.2
 * [new branch]      android-1.6_r1.4 
 * [new branch]      android-1.6_r1.5 
 * [new branch]      android-1.6_r2
 * [new branch]      android-2.0.1_r1
 * [new branch]      android-2.0_r1
 * [new branch]      android-2.1_r1 
 * [new branch]      android-2.1_r2 
 * [new branch]      android-2.2.1_r1
 * [new branch]      android-2.2.1_r2 
 * [new branch]      android-2.2.2_r1  
 * [new branch]      android-2.2.3_r2 
 * [new branch]      android-2.2_r1 
 * [new branch]      android-2.2_r1.3
 * [new branch]      android-2.3.1_r1 
 * [new branch]      android-2.3.3_r1
 * [new branch]      android-2.3.3_r1.1
 * [new branch]      android-2.3.4_r1
 * [new branch]      android-2.3.5_r1
 * [new branch]      android-2.3.6_r1
 * [new branch]      android-2.3.7_r1
 * [new branch]      android-2.3_r1
 * [new branch]      android-4.0.1_r1 
 * [new branch]      android-4.0.1_r1.1
 * [new branch]      android-4.0.1_r1.2
 * [new branch]      android-4.0.2_r1 
 * [new branch]      android-4.0.3_r1 
 * [new branch]      android-4.0.3_r1.1
 * [new branch]      android-4.0.4_r1 
 * [new branch]      android-4.0.4_r1.1 
 * [new branch]      android-4.0.4_r1.2
 * [new branch]      android-cts-2.2_r8
 * [new branch]      android-cts-2.3_r10
 * [new branch]      android-cts-2.3_r11
 * [new branch]      android-cts-2.3_r12
 * [new branch]      android-cts-4.0.3_r1
 * [new branch]      android-cts-4.0_r1
sudo ./repo sync //同步代碼樹,次過程比較長,公司網速快,約3小時


2. 配置linux編譯環境 & compile
1). 依賴包
sudo apt-get install git-core curl
sudo apt-get install gnupg flex bison gperf build-essential zip zlib1g-dev gcc-multilib g++-multilib libsdl-dev libesd0-dev libwxgtk2.6-dev
sudo apt-get install valgrind
sudo apt-get install libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev
sudo apt-get install libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown
sudo apt-get install libxml2-utils xsltproc
sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so


2)由於android源碼編譯要求爲4.3,而系統默認gcc版本爲4.4,那你的編譯可能會失敗的!我的系統是ubuntu 10.10,默認的gcc版本爲4.4,gcc-4.4太嚴格,不能將const char* 轉爲char*.那麼怎樣從gcc-4.4降到gcc- 4.3呢?
a)、安裝gcc-4.3
$ sudo apt-get install gcc-4.3 g++-4.3
b)、修gcc相關鏈接
$ cd /usr/bin
sudo ln -snf gcc-4.3 gcc
sudo ln -snf g++-4.3 g++
sudo ln -snf cpp-4.3 cpp


3)android2.2要求用SUN JDK5
修改/etc/profile註銷重新登錄後生效


4)編譯android
make -j 2 (雙核)
大約兩個小時,出現以下信息時結束
target Non-prelinked: sensors.trout (out/target/product/generic/symbols/system/lib/sensors.trout.so)
target Strip: sensors.trout (out/target/product/generic/obj/lib/sensors.trout.so)
Generated: (out/target/product/generic/android-info.txt)
Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_unopt_intermediates/system.img
Install system fs image: out/target/product/generic/system.img
Target ram disk: out/target/product/generic/ramdisk.img
Target userdata fs image: out/target/product/generic/userdata.img
Installed file list: out/target/product/generic/installed-files.txt


3. 編譯sdk(可選)
上述make沒有編譯sdk和linux內核(給我們與編譯好內核了./prebuilt/android-arm/kernel/kernel-qemu)
make sdk
編譯過程中可能會遇到的問題。
問題一:找不到bios.bin和vgabios-cirrus.bin文件
couldn't locate source file: usr/share/pc-bios/bios.bin
couldn't locate source file: usr/share/pc-bios/vgabios-cirrus.bin
注意,這裏的usr/share目錄指的是~/Android/out/host/linux-x86目錄下的usr/share目錄,修改辦法是複製~/Android/prebuilt/common下的pc-bios文件夾到~/Android/out/host/linux-x86/usr/share即可:
USER-NAME@MACHINE-NAME:~/Android$ cp ~/Android/prebuilt/common/pc-bios ~/Android/out/host/linux-x86/usr/share
問題二:找不到ddmlib-tests.jar、 ninepath-tests.jar 、common-tests.jar 和sdkuilib-tests.jar文件
在~/Android/out/host/linux-x86/framework這個目錄下,可以找到以下幾個文件common.jar、ddmlib.jar、ninepatch.jar、sdkuilib.jar這四個文件,然後將它們分別複製一份,並重命名,命名的原則很簡單,就是在原有的名字後面跟上-tests即可。


4. 安裝編譯好的Android鏡像到模擬器上。
1) 環境變量
export PATH=$PATH:~/android_src/out/host/linux-x86/bin
export ANDROID_PRODUCT_OUT=~/android_src/out/target/product/generic
其中,~/Android/out/host/linux-x86/bin有我們要執行的emulator命令,而~/Android/out/target/product/generic是Android鏡像存放目錄,下面執行emulator命令時會用到。


2)運行模擬器
emulator
直接敲上面的命令即可。模擬器運行需要四個文件,分別是Linux Kernel鏡像zImage和Android鏡像文件system.img、userdata.img和ramdisk.img。執行emulator命令時,如果不帶任何參數,則Linux Kernel鏡像默認使用~/Android/prebuilt/android-arm/kernel目錄下的kernel-qemu文件,而Android鏡像文件則默認使用ANDROID_PRODUCT_OUT目錄下的system.img、userdata.img和ramdisk.img,也就是我們剛剛編譯出來的鏡像問題。
*當然,我們也可以以指定的鏡像文件來運行模擬器,即運行emulator時,即:
emulator -kernel ./prebuilt/android-arm/kernel/kernel-qemu -sysdir ./out/target/product/generic -system system.img -data userdata.img -ramdisk ramdisk.img


*我們也可自己編譯linux內核
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章