Download Android Source Code and Build

Download Android Source Code and Build

Basic Infomation

  • OS: Ubuntu 16.4 LTS
  • Android Branch: android-7.1.2_r33
  • Device: Google Pixel One

Installing OpenJDK

1
2
3
4
5
6
android@android-pc:~$ sudo apt-get update
android@android-pc:~$ sudo apt-get install openjdk-8-jdk
## Configures the default for the java and javac
android@android-pc:~$ sudo update-alternatives --config java
android@android-pc:~$ sudo update-alternatives --config javac

Installing Required Packages

1
android@android-pc:~$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip

Installing Android Platform Tools

1
2
3
4
5
6
7
8
android@android-pc:~$ wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
android@android-pc:~$ unzip platform-tools-latest-linux.zip -d ~/androidTools
android@android-pc:~$ vim ~/.bashrc
## 於文件最下方加入以下語句,讓Android tools可以在任何位置被使用
ANDROID_TOOLS="~/androidTools"
export PATH=$ANDROID_TOOLS/bin:$PATH
android@android-pc:~$ source ~/.bashrc

Init Git Information

1
2
3
android@android-pc:~$ sudo apt-get install git
android@android-pc:~$ git config --global user.name "Your Name"
android@android-pc:~$ git config --global user.email "you@example.com"

Installing Repo

1
2
3
4
5
6
7
8
9
10
11
12
android@android-pc:~$ mkdir ~/bin
android@android-pc:~$ vim ~/.bashrc
## 於文件最下方加入以下語句,讓repo可以在任何位置被使用
export PATH=~/bin:$PATH
android@android-pc:~$ source ~/.bashrc
## 下載repo,並儲存成~/bin/repo
android@android-pc:~$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
## 賦予repo執行權限
android@android-pc:~$ sudo chmod a+x ~/bin/repo

Initializing a Repo client

1
2
3
4
5
android@android-pc:~$ mkdir androidSource
android@android-pc:~$ cd androidSource
android@android-pc:~/androidSource$ mkdir android-7.1.2_r33
android@android-pc:~/androidSource$ cd android-7.1.2_r33
android@android-pc:~/androidSource/android-7.1.2_r33$ repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r33 --depth=1

Downloading the Android Source Tree

1
2
3
android@android-pc:~/androidSource/android-7.1.2_r33$ repo sync -j8
# wait for a long time
Syncing work tree: 100% (528/528), done.

Installing Device Driver

1
2
3
4
5
android@android-pc:~/androidSource/android-7.1.2_r33$ tar -zxvf qcom-sailfish-nzh54d-56bb51e3.tgz
android@android-pc:~/androidSource/android-7.1.2_r33$ ./extract-qcom-sailfish.sh
android@android-pc:~/androidSource/android-7.1.2_r33$ tar -zxvf google_devices-sailfish-nzh54d-cc9ac173.tgz
android@android-pc:~/androidSource/android-7.1.2_r33$ ./extract-google_devices-sailfish.sh

Buiding Android Source

  • lunch 後選擇目標Device的代號,Device code name 可以參考selecting-device-build
    • 例如Pxiel的Code name 爲sailfish,所以選擇18.aosp_sailfish-userdebug
  • 若之後修改了Android source code,要進行重新編譯,則進行此步驟即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
android@android-pc:~/androidSource/android-7.1.2_r33$ source build/envsetup.sh
## 若已經知道Code name,可以直接使用 lunch 18
android@android-pc:~/androidSource/android-7.1.2_r33$ lunch
Youre building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_mips-eng
4. aosp_mips64-eng
5. aosp_x86-eng
6. aosp_x86_64-eng
7. full_fugu-userdebug
8. aosp_fugu-userdebug
9. mini_emulator_arm64-userdebug
10. m_e_arm-userdebug
11. m_e_mips-userdebug
12. m_e_mips64-eng
13. mini_emulator_x86-userdebug
14. mini_emulator_x86_64-userdebug
15. aosp_dragon-userdebug
16. aosp_dragon-eng
17. aosp_marlin-userdebug
18. aosp_sailfish-userdebug
19. aosp_flounder-userdebug
20. aosp_angler-userdebug
21. aosp_bullhead-userdebug
22. hikey-userdebug
23. aosp_shamu-userdebug
Which would you like? [aosp_arm-eng] 18
make -j4
## wait for a long time
#### make completed successfully (61:14 (mm:ss)) ####

Referance

Google Android Developers: