— 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 fontconfig
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:
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 Type-C) will be comparatively slow. Here we go:
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!
Thank you, this is very useful
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.
could you do a guide for ubuntu 19.04 please??
Hey, so this worked great just as instructed on 18.04LTS booted on the metal on my desktop PC (i7-6700K, 32GB ram, 512GB samsung 850 pro that wasn’t being used for anything else), so I wanted to see if it worked okay virtualized so that I could just pause things and go back to desktop for letting my kiddo play portal/minecraft, apply current updates, and so forth).
After 4-5 days of trying wayyyyy too many times to get this to work in various VM environments with Ubuntu server (14, 16, 18, multipass/hyperkit on my macbook pro under catalina, multipass/hyperv on my windows desktop, hyperv manager-created gen2 vm on windows desktop so I could actually put it on the drive I wanted [c’mon Canonical; hard-coded file paths instead of a default & option to specify VM locations on the host filesystem?], virtualbox vm on both machines [after having to use bcdedit to disable hyperv]) only to have it fail toward the end with null pointer exceptions from openjdk…
Long story short, turns out that you need “fontconfig” as well, since openjdk (system-provided or the prebuilt one that repo syncs) depends on it (or at least for it to have generated a config file in the $JAVA_HOME directory) in order to successfully finish manipulating fonts toward the end of the build process without getting a null pointer exception; which is of course installed by default with a desktop image of Ubuntu, but not the server images.
Here’s a link better explaining it: https://bugzilla.redhat.com/show_bug.cgi?id=1711256
TL;DR: if you’re using ubuntu server in order to save resources in a VM build environment, install “fontconfig” as well to make sure it’ll complete.