This page will introduce you to how you can download and build the Android source tree to customize it for your usage.

If you have not built Android on your desktop yet, please read Android's official build environment set up guide carefully before you proceed. Otherwise, you may have unexpected errors and will need to read a quite long and complicated build log to find the problem.

We've used Ubuntu 16.04 64bit with 8GB RAM since other newer versions had some issues while building the Android OS.

If you want to build full Android source tree, don't download & build the kernel source separately.
Separated Kernel build might break the Android build process.

Install the openjdk-8-jdk

If your build environments is Ubuntu 14.04 or 12.04, enter the followings.

$ sudo add-apt-repository ppa:openjdk-r/ppa
$ sudo apt-get update

And you can install the openjdk-8-jdk by the apt.

$ sudo apt-get install openjdk-8-jdk
$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

If you have more the one Java versions installed, you can change the java version.

$ sudo update-alternatives --config java
$ sudo update alternatives --config javac

Install the cross compiler

Click one of the site to download toolchain to build Android.

Once the download is done, extract the tarball to /opt/toolcahins/.

$ sudo mkdir -p /opt/toolchains
$ sudo tar zxvf aarch64-linux-android-4.9.tar.gz -C /opt/toolchains/

In order to add the toolchain path to PATH, paste below lines to $HOME/.bashrc.

export PATH=/opt/toolchains/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/:$PATH

You can apply the change if you login again or import to apply this change, login again or evaluate $HOME/.bashrc with source command.

$ source ~/.bashrc

You can check if the toolchain installed above works properly while checking the version of toolchain.
If you can find gcc version 4.9.x-google 20140827 (prerelease) at the end of the line, the toolchain is well installed.

$ aarch64-linux-android-gcc -v
Using built-in specs.
Target: aarch64-linux-android
Configured with: /tmp/AOSP-toolchain/build/../gcc/gcc-4.9/configure --prefix=/tmp/ndk-xur/build/toolchain/prefix --target=aarch64-linux-android --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/tmp/ndk-xur/build/toolchain/temp-install --with-mpfr=/tmp/ndk-xur/build/toolchain/temp-install --with-mpc=/tmp/ndk-xur/build/toolchain/temp-install --with-cloog=/tmp/ndk-xur/build/toolchain/temp-install --with-isl=/tmp/ndk-xur/build/toolchain/temp-install --with-ppl=/tmp/ndk-xur/build/toolchain/temp-install --disable-ppl-version-check --disable-cloog-version-check --disable-isl-version-check --enable-cloog-backend=isl --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --disable-libitm --enable-initfini-array --disable-nls --prefix=/tmp/ndk-xur/build/toolchain/prefix --with-sysroot=/tmp/ndk-xur/build/toolchain/prefix/sysroot --with-binutils-version=2.25 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1 --with-gmp-version=5.0.5 --with-gcc-version=4.9 --with-gdb-version=7.7 --with-gxx-include-dir=/tmp/ndk-xur/build/toolchain/prefix/include/c++/4.9 --with-bugurl= --disable-bootstrap --enable-plugins --enable-libgomp --enable-gnu-indirect-function --disable-libsanitizer --enable-gold --enable-ld=default --enable-threads --enable-graphite=yes --with-cloog-version=0.18.0 --with-isl-version=0.11.1 --enable-eh-frame-hdr-for-static --enable-fix-cortex-a53-835769 --program-transform-name='s&^&aarch64-linux-android-&' --enable-gold
Thread model: posix
gcc version 4.9.x-google 20140827 (prerelease) (GCC)

Install the required packages

You need to install more required packages.

$ sudo aptitude install libcurl4-openssl-dev nss-updatedb git
  • Visit this link to install the repo.

  • Downloaded Android full source code size is around 70GB. Prepare enough space before building the Android platform.

This command will initiate to download the Android source tree for ODROID-N1.
The full source includes u-boot, kernel and Android trees.


$ mkdir <Android Platform Folder Name>
$ cd <Android Platform Folder Name>
$ repo init -u -b rk3399_7.1.2_master
$ repo sync

Please make sure that you've installed cross toolchain for kernel and U-boot before you start to build.

Please follow the build step.

$ export ARCH=arm64
$ export ARCHV=aarch64
$ export CROSS_COMPILE=aarch64-linux-android-
$ export PATH=/opt/toolchains/aarch64-linux-android-4.9/bin:$PATH
$ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
$ export PATH=$JAVA_HOME/bin:$PATH
$ source build/ 
$ lunch odroidn1-eng 
$ make -j12 selfinstall

You can replace the number on the command make for simultaneous compile as much as number of core on your build machine.

How to write images without fastboot on ODROID-XU4(android)

You can not use fastboot on ODROID-XU4, because It doesn't have USB otg port.

So you should flash directly selfinstall image to media. out/target/product/odroidn1/selfinstall-odroidn1/selfinstall-odroidn1.bin

You have to check your media path before flash image. If you mistakes when flashing image, you can brake your system!
In this example, we assume that media device's path is /dev/sdd.

$ sudo dd if=out/target/product/odroidn1/selfinstall-odroidn1.bin of=/dev/sdd bs=1M
$ sync
$ sudo eject /dev/sdd