Build AOSP 8.1.0 on Nexus 6p - An Incomplete Guide
Although Google has posted a perfect tutorial on Building AOSP from the source, I decide to lay down my steps on building android on my Nexus 6p. These are a few unexpected bugs, errors and surprises as well.
- Establishing the environment
- 64-bit Ubuntu 14.04 LTS. You can also try other ubuntu distributions with required build tools, as well as MacOS.
- Installing JDK:
- openjdk-8-jre-headless_8u45-b14-1_amd64.deb
- openjdk-8-jre_8u45-b14-1_amd64.deb
- openjdk-8-jdk_8u45-b14-1_amd64.deb
- download the .deb packages since OpenJDK 8 is not natively supported on Ubuntu 14.04 LTS.
- sudo apt-get update
- sudo dkpg -i xxx.deb | run this command on each of the above downloaded packages
- if there is any missing dependency packages reported, run: sudo apt-get -f install
- Repeat and loop the above two steps to make sure OpenJDK is installed.
- Installing other required packages:
-
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
-
- Configuring USB access for your devices, in case your are not using an emulator
- plug your android in, go to System-About Phone-Build Number, tap it for seven times and you will see the hidden developer options in the parent menu, allow USB-debugging in developer options
- sudo apt-get install android-tools-adb
- sudo adb devices (allow this action on your phone to get efficient permission)
- change 51_android_rules if the above step does not work
- Using a separate output directory:
- add the following line in your bash profile to make sure this still applies after a reboot:
-
export OUT_DIR_COMMON_BASE=<path-to-your-out-directory>
-
- add the following line in your bash profile to make sure this still applies after a reboot:
- Downloading the source
- Installing repo:
- Make sure you have a bin/ directory in your home directory and that it is included in your path:
-
mkdir ~/bin
-
PATH=~/bin:$PATH
-
- Download the Repo tool and ensure that it is executable:
-
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
-
chmod a+x ~/bin/repo
-
- Initializing a Repo client
- Creating an working directory. This would be the directory with all source code and pre-built binaries. Name it carefully.
- mkdir WORKING+DIR && cd WORKING_DIR
- Configuring Git:
- git config --global user.name "xxx"
- git config --global user.email "xxx"
-
repo init -u https://android.googlesource.com/platform/manifest
- Download the source. REMINDER: DON'T download master branch if you do not know your phone's build number. For example, I want to build the latest stable release of Nexus 6p. The most recent build number would be android-8.1.0_r18 on 03/26/2018:
-
repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r18
-
- Download the source. REMINDER: DON'T download master branch if you do not know your phone's build number. For example, I want to build the latest stable release of Nexus 6p. The most recent build number would be android-8.1.0_r18 on 03/26/2018:
- A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a
.repo
directory where files such as the manifest will be kept.
- Creating an working directory. This would be the directory with all source code and pre-built binaries. Name it carefully.
- Downloading the Android Source Tree by: repo sync
- Make sure you have a bin/ directory in your home directory and that it is included in your path:
- Obtain proprietary binaries
- Although Android is free and open-source, there are some hardware-related proprietary libraries required. As for a Google/Nexus phone, you can easily find those binaries here with build number OPM5.171019.017 (android 8.1.0_r18).
- Unzip those binaries, move those two shell script into your working directory and run them. After signing the agreement you would be all set.
- run "make clobber" to ensure a clean source tree without other outputs
- Installing repo:
- Building AOSP from the scratch
- Set up the environment
- source build/envsetup.sh
- lunch
- choose a target, for my case, it would be 28. angler_user_debug
- make -j16, I am using a i7-7700 with 4 cores and 8 threads. Hence any argument between 16-32 should be fine for make
- Running builds on your devices
- make adb fastboot if you haven't had them installed before
- unlock your device if it is not already unlocked
- fastboot flashing unlock
- flash the built images!
- sudo adb reboot bootloader
- fastboot flashall -w
- So far, my Nexus 6p works just fine on unmodified AOSP build version but stuck at boot screen if source code is modified even slightly.
- In case something goes wrong and there should be a backup plan:
- Restoring devices to factory state
- Download the factory image here.
- Make sure your phone is connected by "fastboot devices"
- Unzip the image and run the ./flashall.sh inside the directory
- Restoring devices to factory state
- Set up the environment
- Other errors:
- Previously I was using a crappy laptop so most of the time buildings didn't go smoothly as it is now on a desktop. And below are some errors I hope you would not encounter.
- Jack server out of memory error, try increase heap size:
-
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g" ./prebuilts/sdk/tools/jack-admin kill-server ./prebuilts/sdk/tools/jack-admin start-server
-
- system image too large error: Try a swap file to increase memory space or change the settings in a make file to pre-install less Google service packages
Comments