Full instructions are here: https://source.android.com/setup/build/building

Build OS Ubuntu 18.04.3 Virtual Box VM.

  • Increased mem from 8G to 12G.
  • Increased swap from 2G to 4G.
  • 6 CPUs allocated to VM.
  • Build takes up 155G disk space. (Completed build with 16G free)

Packages (from http://wiki.t-firefly.com/en/Firefly-RK3399/compile_android8.1_firmware.html)

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get install openjdk-8-jdk
sudo apt-get install gcc-arm-linux-gnueabihf  lzop libncurses5-dev  libssl1.0.0 libssl-dev
sudo apt-get install gcc-arm-linux-gnueabihf   libssl1.0.0 libssl-dev   p7zip-full
sudo apt-get install git-core gnupg flex bison gperf libsdl1.2-dev   libesd0-dev libwxgtk2.8-dev squashfs-tools build-essential zip curl   libncurses5-dev zlib1g-dev pngcrush schedtool libxml2 libxml2-utils   xsltproc lzop libc6-dev schedtool g++-multilib lib32z1-dev lib32ncurses5-dev   lib32readline-gplv2-dev gcc-multilib libswitch-perl

Also needed LLVM.

sudo apt-get install clang

Initial source download setup.

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
sha256sum ~/bin/repo
chmod a+x ~/bin/repo
repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r72
repo sync

Updated build/envsetup.sh. Added this to end:

export LC_ALL=C
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

(Fixes from https://stackoverflow.com/questions/51324238/aosp-build-stopped-subcommand-failed and https://stackoverflow.com/questions/35579646/android-source-code-compile-error-try-increasing-heap-size-with-java-option)

Sometimes Jack needs to be re-installed:


cd ./prebuilts/sdk/tools/ 
./jack-diagnose
./jack-admin install-server jack-launcher.jar jack-server-4.11.ALPHA.jar


source ./build/envsetup.sh
lunch aosp_arm64-eng
m droid

Cleaning up:

m clean
repo status
rm -rf out/
repo sync
repo forall -vc "git reset --hard"
repo forall -vc "git clean -f -d -x"