— For a ready-to-go Virtual Machine based on these instructions, check out this post!—
With a new version of Ubuntu comes an update to my guide for setting up a build environment to compile Android ROMs. The aim of this is to simplify the configuration process and teach a little bit about the command line. It’s ten easy steps! Of course, this could be boiled down to a two-liner with some CLI wizardry, but that isn’t the point.
Follow the directions in order. Copy and paste the code, or better yet, type it out for an improved learning experience.
This guide applies to all variations of Ubuntu 16.04 LTS Xenial Xerus 64 bit. Do not use the 32 Bit version.
Also, PAY CLOSE ATTENTION when to use “sudo” and when to not.
Much thanks goes out to Google, ProTekk, Canonical, and everyone else that I read a random paragraph here and snippet there.
1) Unless it’s a completely fresh Ubuntu installation, the wrong version of Java might be installed. Let’s fix that first.
The command below makes sure you’re starting with a clean slate. Copy and paste it into a terminal (command prompt) window:
sudo apt-get remove openjdk-* icedtea-*
If necessary, follow the on-screen instructions to remove any stray Java versions. Otherwise, move on to the next step.
2) Install the main build tools with this command:
sudo apt-get install git ccache automake lzop bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 g++-multilib python-networkx libxml2-utils bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev squashfs-tools pngcrush schedtool dpkg-dev liblz4-tool make optipng maven
3) “repo” communicates with git servers for all that precious source code. The next command will grab it:
mkdir ~/bin && curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo && chmod a+x ~/bin/repo
4) Use a favorite text editor to open ~/.bashrc (or equivalent) – nano is easy to use:
5) At the very bottom (use the Page Down key) paste this code to a new line:
export PATH=~/bin:$PATH export USE_CCACHE=1
6) Save it. In nano that would be Ctrl-O and then Enter. Then Ctrl-X to exit back to a prompt. Restart the shell:
7) In the terminal, make a folder to download the Android source code. The commands below will keep it in the home directory, but if limited on space it’s ok to create it somewhere else. Faster is better, i.e. NVMe would be best, USB (even 3.0) will be comparatively slow. Here we go:
mkdir ~/android cd ~/android
8) Now initialize the repo. Decide the flavor of Android to build, i.e. AOKP, CyanogenMod, AOSP etc. For the purposes of this tutorial, here’s the command for Cyanogenmod 13 (Marshmallow) :
repo init -u https://github.com/CyanogenMod/android.git -b cm-13.0
9) Time to get the source, many gigabytes of downloading await. Don’t worry, it’s automated.
Check back periodically every hour or so. It all depends on how fast the connection is.
10) Now, for Java. Some ROMs (Android Lollipop / CM 12.1 and below) require OpenJDK 7. Marshmallow / CM 13 and above require OpenJDK 8. If building for reallllllly old devices, OpenJDK 6. Here’s the easiest way to install on Ubuntu 16.04.
Add the PPA for OpenJDK:
sudo add-apt-repository ppa:openjdk-r/ppa
Then, install the appropriate version of Java. In this case we’re going to use 7, because it’s popular. Simply replace openjdk-7-jdk with 6 or 8 as needed.
sudo apt-get update && sudo apt-get install openjdk-7-jdk
That’s it! Everything should be ready to go.
Donate to the new hardware fund here. Thanks for reading!