[HOW TO] Setup Ubuntu 20.04 LTS Focal Fossa to Compile Android ROMs

— For a ready-to-go Virtual Machine based on these instructions, check out this post!

The aim of this guide is to simplify the configuration process and teach a little bit about the command line. It’s less than ten 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 20.04 LTS Focal Fossa 64 bit.

Also, PAY CLOSE ATTENTION when to use “sudo”.

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 lzop bison build-essential zip curl zlib1g-dev g++-multilib libxml2-utils bzip2 libbz2-dev libghc-bzlib-dev squashfs-tools pngcrush liblz4-tool optipng libc6-dev-i386 gcc-multilib libssl-dev gnupg flex lib32ncurses-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev xsltproc unzip libffi-dev libxml2-dev libxslt1-dev libjpeg8-dev fontconfig libncurses5-dev libncurses5 libncurses5:i386 python-is-python3

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:

nano ~/.bashrc

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:

source ~/.bashrc

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 Type-C) 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. LineageOS, AOSP etc. For the purposes of this tutorial, here’s the command for Android Pie’s GSI branch :

repo init -u https://android.googlesource.com/platform/manifest -b pie-gsi

9) Time to fetch the source, many gigabytes of downloading await. Don’t worry, it’s automated.

repo sync -cq

Check back periodically every hour or so. It all depends on how fast the connection is.

That’s it! Everything should be ready to build.

Donate to the new hardware fund here. Thanks for reading!

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.