[HOW TO] Setup Ubuntu 18.04 LTS Bionic Beaver 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 18.04 LTS Bionic Beaver 64 bit. Do not use the 32 Bit version.

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 gperf build-essential zip curl zlib1g-dev g++-multilib python-networkx libxml2-utils bzip2 libbz2-dev libghc-bzlib-dev squashfs-tools pngcrush liblz4-tool optipng libc6-dev-i386 gcc-multilib libssl-dev gnupg flex lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev xsltproc unzip python-pip python-dev libffi-dev libxml2-dev libxslt1-dev libjpeg8-dev openjdk-8-jdk

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!

  2 comments for “[HOW TO] Setup Ubuntu 18.04 LTS Bionic Beaver to Compile Android ROMs

  1. Inanh
    June 1, 2019 at 12:27 pm

    Thank you, this is very useful

  2. Eric Richards
    June 10, 2019 at 1:37 pm

    I’m having no problem building my AOSP. Where everything falls down is when I try to flash it to SD.

    Processor: NXP i.MX6, reference board: Sabre SD, work environment 18.04 LTS (for flashing), 16.04 LTS.

    Disk images always fail. Uboot runs and then fails with: Error loading zImage. Bad magic.

    The disk images look good on the system. The SD card always looks like garbage.

    Doing this same flash on 16.04 LTS works perfectly. (We have a mix of old machines and newer ones. Builds actually take place within a 16.04 Docker container, regardless of the host platform.)

    I am open to suggestions. I have left messages with NXP, Stack Overflow, and, now here.

Leave a Reply

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.