转自: http://apk.tw/thread-460766-1-1.html
http://apk.tw/thread-466419-1-1.html
個人因為一些工作和家庭的因素離開一陣子
現在比較有空開始發一些之前就想PO的一些如何從原碼編譯的文章
如果文章內容有不足的地方還請各方高手不吝指教
編譯cm11最好在Linux作業系統上編譯
至於windows或是mac要如何編譯要牽扯到的設定非常複雜在這邊就不討論
個人推荐用Ubuntu 13.10或Linux Mint 16作業系統編譯
請自行上網google相關文章要如何安裝Linux作業系統
注意電腦使用的Linux作業系統版本最好是64-bit的
並且至少有4G的記憶體,原碼會佔用約20G的硬碟空間請確保家目錄同步完原碼後至少還有20G的空間可用
否則編譯的過程會有問題無法順利編譯
教學開始
1.在終端機(terminal)下輸入下列指令,移除OpenJDK
- sudo apt-get purge openjdk-* icedtea-* icedtea6-*
- sudo add-apt-repository ppa:webupd8team/java
- sudo apt-get update && sudo apt-get install oracle-java6-installer
3.安裝編譯cm11的所需要的套件
- sudo apt-get install bison build-essential curl flex g++-multilib gcc-multilib git-core gnupg gperf lib32ncurses5-dev lib32readLine-gplv2-dev lib32z1-dev libesd0-dev libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop squashfs-tools xsltproc pngcrush schedtool zip zlib1g-dev
4.安裝設定repo,這個是google發展出來的Android原碼版本控制工具
- mkdir ~/bin
- PATH=~/bin:$PATH
- cd ~/bin
- curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
- chmod a+x ~/bin/repo
- cd
5.建立cm11工作目錄
- mkdir cm-11
- cd cm-11
6.初始化repo,cm11原碼
- repo init -u git://github.com/CyanogenMod/android.git -b cm-11.0
7.
同步cm11原碼,此步驟約須下載約10G的原碼資料,並佔用約20G的硬碟空間,請耐心等待
- repo sync
備註:
repo可斷點續傳,如果同步的過程太花時間可同時按下ctrl+z結束原碼同步的動作
下次再執行下列指令重新同步上次斷掉的地方繼續同步原碼
- repo sync
今天的教學到此為止
下回繼續繼續介紹如何編譯cm11
延續上一篇同步完原碼後
接下來的工作就是開始編譯新的cm11
後續的動作會因為不同的機型
步驟方式會有所不同
今天介紹的是比較簡單的方式
直接用高手已經整理過的原碼(請自行上網蒐集你的機型其他高手寫好的原碼)
例如你手機的Device tree,vendor tree,hardware tree,內核(kernel)內核架構等
如果你的手機cm11官方有資源可以嘗試直接從步驟4開始
教學開始
步驟1:
建立自己手機的Device tree
- cd device
- mkdir sony
- cd sony
- git clone [url=http://012.tw/cxEFOW7]https://github.com/Andrewas/Android_device_sony_kumquat.git[/url] -b cm-11.0 kumquat
- cd ../..
建立自己手機的vendor tree,hardware tree,內核(kernel)架構
- cd vendor
- mkdir sony
- cd sony
- git clone [url=http://012.tw/lnrvKM4]https://github.com/XperiaNovathor/proprietary_vendor_sony.git[/url] -b master kumquat
- cd ../..
- cd hardware
- git clone [url=http://012.tw/iqstSV2]https://github.com/XperiaNovathor/android_hardware_semc.git[/url] -b master semc
- cd ..
- mkdir -p kernel/sony
- cd kernel/sony
- git clone [url=http://012.tw/anvJR89]https://github.com/XperiaNovathor/android_kernel_xperiago.git[/url] -b cm-11 u8500
- cd ../..
接下來定義編譯時所調用的檔案路徑為自己手機的架構,而非cm11預設的
- patch -p1 < hardware/semc/patches/framework_av.patch
- patch -p1 < hardware/semc/patches/framework_native.patch
- patch -p1 < hardware/semc/patches/framework_base.patch
- patch -p1 < hardware/semc/patches/hardware_libhardware.patch
- patch -p1 < hardware/semc/patches/hardware_libhardware_legacy.patch
- patch -p1 < hardware/semc/patches/system_core.patch
- patch -p1 < hardware/semc/patches/bionic.patch
- patch -p1 < hardware/semc/patches/bootable_recovery.patch
- patch -p1 < hardware/semc/patches/external_bluetooth_bluedroid.patch
- patch -p1 < hardware/semc/patches/packages_apps_Bluetooth.patch
下載初始化編譯cm11所需的檔案架構設定
- cd vendor/cm
- ./get-prebuilts
- cd ../..
開始編譯
- . build/envsetup.sh
- lunch cm_kumquat-userdebug
- make -j4 otapackage
cpu規格比較好超過4核心的
可考慮將-j4改為-j8
利用更多執行緒去編譯可縮短編譯的時間
我的筆電規格為Intel Core i5-3230M
8G DDR3
總共編譯的時間約為2個半小時
下面的指令為你編譯新的cm11時需要執行的指令(例如同步最新的cm11原碼)
步驟1:
首先清除之前編譯時所產生的所有檔案
- cd cm-11
- make clean
然後重新定義路徑和同步最新的原碼
- patch -p1 -R < hardware/semc/patches/framework_av.patch
- patch -p1 -R < hardware/semc/patches/framework_native.patch
- patch -p1 -R < hardware/semc/patches/framework_base.patch
- patch -p1 -R < hardware/semc/patches/hardware_libhardware.patch
- patch -p1 -R < hardware/semc/patches/hardware_libhardware_legacy.patch
- patch -p1 -R < hardware/semc/patches/system_core.patch
- patch -p1 -R < hardware/semc/patches/bionic.patch
- patch -p1 -R < hardware/semc/patches/bootable_recovery.patch
- patch -p1 -R < hardware/semc/patches/external_bluetooth_bluedroid.patch
- patch -p1 -R < hardware/semc/patches/packages_apps_Bluetooth.patch
- repo forall -p -c "git checkout -f"
- repo sync
- patch -p1 < hardware/semc/patches/framework_av.patch
- patch -p1 < hardware/semc/patches/framework_native.patch
- patch -p1 < hardware/semc/patches/framework_base.patch
- patch -p1 < hardware/semc/patches/hardware_libhardware.patch
- patch -p1 < hardware/semc/patches/hardware_libhardware_legacy.patch
- patch -p1 < hardware/semc/patches/system_core.patch
- patch -p1 < hardware/semc/patches/bionic.patch
- patch -p1 < hardware/semc/patches/bootable_recovery.patch
- patch -p1 < hardware/semc/patches/external_bluetooth_bluedroid.patch
- patch -p1 < hardware/semc/patches/packages_apps_Bluetooth.patch
開始編譯新的cm11
- . build/envsetup.sh
- lunch cm_kumquat-userdebug
- make -j4 otapackage
教學結束
之後會陸續介紹如何移植修改recovery,內核等
以及詳細的原碼架構等
如果我有解釋不清楚或錯誤的地方
還請各位高手不令指教