版權聲明:本文爲博主原創文章,未經博主允許不得轉載。
1 安裝git&repo&curl
下載Android源碼需要git,repo等工具,啓動repo是Google寫的一個專門用於下載Android源碼的工具,主要調用了git。
(1)安裝git
- sudo apt-get install git
下載repo,改變可執行權限,然後移動到/usr/bin目錄中即可:
- chomd +x repo
- sudo mv repo /usr/bin
2 下載Android
由於Google被牆了,因此無法直接從Google官網下載Android源碼,因此需要另覓途徑,高通開源網是一個不錯的選擇。本文在其中下載支持高通msm8909平臺的Android源碼,Android版本爲6.0.1,詳細步驟如下:
1)創建源碼目錄
- mkdir android-msm8909
- cd android-msn8909
- repo init -u git://codeaurora.org/platform/manifest.git -b release -m LA.BR.1.2.6.c1-02100-8x09.0.xml
- repo sync -j4
a)源碼大小有40GB,下載過程要幾個小時;
b)上述LA.BR.1.2.6.c1-02100-8x09.0.xml在高通開源網上查看:
3 編譯Android
3.1 安裝JDK
通過《Android源碼編譯--jdk版本查詢》的方法查看上述源碼所需的JDK版本,得知需要安裝OpenJDK-1.7:
- sudo apt-get install openjdk-7-jdk
3.2 編譯
1)進入android-msm8909目錄:
- cd android-msm8909
2)配置環境變量:
- source build/envsetup.sh
3)執行下面命令選擇產品:
- lunch
在上圖中選擇一個版本(我選擇了27),然後按回車鍵即可。
4)執行下面命令啓動編譯:
- make
或
- make -j4 showcommands dist
參數說明:
-j4, 開啓4個線程;
showcommands, 顯示編譯過程中執行的命令[38];
dist, 將編譯後產生的發佈文件拷貝到out/dist目錄中[38];
3.3 編譯結果
編譯完成後,生產的相關鏡像在out/target/product的子目錄中,例如:
其中,linux內核編譯結果保存在obj/KERNEL_OBJ目錄中(Linux內核也一同被編譯了,而無需另外獨立編譯!)。
4 編譯sdk
詳見《Android源碼編譯SDK》。
5 編譯內核
- make bootimage
6 編譯其它模塊
參考資料[37]總結了編譯各個模塊的方法:
- make sdk - build the tools that are part of an SDK (adb, fastboot, etc.)
- make snod - build the system image from the current software binaries
- make services
- make runtime
- make droid - make droid is the normal build.
- make all - make everything, whether it is included in the product definition or not
- make clean - remove all built files (prepare for a new build). Same as rm -rf out/<configuration>/
- make modules - shows a list of submodules that can be built (List of all LOCAL_MODULE definitions)
- make <local_module> - make a specific module (note that this is not the same as directory name. It is the LOCAL_MODULE definition in the Android.mk file)
- make clean-<local_module> - clean a specific module
- make bootimage TARGET_PREBUILT_KERNEL=/path/to/bzImage - create a new boot image with custom bzImage
參考資料
[1]Ubuntu 下載 & 編譯 Android5.1 源碼
[3]在Ubuntu系統中下載Android源碼(5.1.1_r8)
[6]下載android4.4.2源碼全過程(附已下載的源碼)
[8]基於Ubuntu 14.04 LTS編譯Android4.4.2源代碼
[10]高通android平臺源碼 (2011-03-28 10:56)
[11]在官網途徑無法下載到android 源碼時,,你可通過這種方式去下載
[13]Android for MSM Project
[14]Qualcomm平臺android開發總結
[15]高通平臺android開發總結 MSM平臺上的AMSS
[16] android源碼下載(上)
[17]android源碼下載(下)
[18]開源代碼下載路徑
[19]如何下載並編譯Android4.0內核源碼goldfish(圖文)
[20]Android源碼、內核編譯
[21]如何下載Android kernel內核源代碼,編譯燒寫驗證
[24]在Ubuntu 14.04系統中編譯Android 5.1.1源碼
[25]Android AOSP 5.1.0 & 5.0.1源代碼百度雲下載
[28]Android學習系列(38)--Android源碼下載和編譯
[33]android編譯SDK問題彙總
[34]如何在linux下編譯windows版android sdk
[35]ubuntu12.04(64bit)編譯android4.2.2源代碼及SDK步驟