為了編譯安卓源碼,首先需要一個Linux,本次采用Ubuntu Kylin14.04,內核版本3.13。裝在四核、4G內存、1T硬盤的虛擬機上
查看內核版本號:
$uname -all
清華鏡像地址
清華鏡像站的速度還是比較快的,地址:
git://aosp.tuna.tsinghua.edu.cn/android/
使用瀏覽器訪問:
http://aosp.tuna.tsinghua.edu.cn/android/
下載 repo
$git clone git://aosp.tuna.tsinghua.edu.cn/Android/git-repo.git/
修改repo
$vi /git-repo.git/repo
google的地址
REPO_URL = ‘https://gerrit.googlesource.com/git-repo’
改為清華大學的地址
REPO_URL = ‘git://aosp.tuna.tsinghua.edu.cn/android/git-repo’
下載 manifest
google 的地址
$ repo init -u https://android.googlesource.com/platform/manifest
改為清華大學的地址
$ repo init -u git://aosp.tuna.tsinghua.edu.cn/android/platform/manifest
如果需要設置版本,加入參數-b 安卓源碼版本號即可。
$ repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-4.0.1_r1
同步源碼
$repo sync [-j4]
后面-j4表示4個線程進行下載,清華鏡像允許最多4線程下載,不要超過4個。
如果中間發現斷掉了或者報錯了,不要緊張,重新運行一下。源碼大小
Set up environment(設置環境變量)
Initialize the environment with the envsetup.sh script. Note that replacing source with . (a single dot) saves a few characters, and the short form is more commonly used in
documentation.
$ source build/envsetup.sh or $ . build/envsetup.sh
Choose a Target(選擇平台編譯)
Choose which target to build with lunch. The exact configuration can be passed as an argument. For example, the following command:$ lunch aosp_arm-eng
refers to a complete build for the emulator, with all debugging enabled.
If run with no arguments lunch will prompt you to choose a target from the menu.
All build targets take the form BUILD-BUILDTYPE, where the BUILD is a codename referring to the particular feature combination.
The BUILDTYPE is one of the following:
Build the code(構建代碼)
Build everything with make. GNU make can handle parallel tasks with a -jN argument, and it's common to use a number of tasks N that's between 1 and 2 times the number of
hardware threads on the computer being used for the build. For example, on a dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), the fastest builds are made
with commands between make -j16 and make -j32.
$ make -j4
最后運行我們剛剛編譯出來的android系統Run It!
You can either run your build on an emulator or flash it on a device. Please note that you have already selected your build target with lunch, and it is unlikely at best to
run on a different target than it was built for.
Flash a Device(燒進一個真實的設備)
To flash a device, you will need to use fastboot, which should be included in your path after a successful build. Place the device in fastboot mode either manually by holding
the appropriate key combination at boot, or from the shell with
$ adb reboot bootloader
Once the device is in fastboot mode, run
$ fastboot flashall -w
The -w option wipes the /data partition on the device; this is useful for your first time flashing a particular device but is otherwise unnecessary.
For more information about building for and running on actual hardware, see Running Builds.
Emulate an Android Device(模擬一個安卓設備)
The emulator is added to your path automatically by the build process. To run the emulator, type
emulator模擬器能成功運行起來的前提是:成功將emulator所在的目錄和 android編譯完之后輸出目錄out下面的host和target目錄都添加到了你的PATH環境變量了。
並且執行source build/envsetup.sh ;lunch sdk-eng;這2個命令。
$ emulator