[HOWTO] Setup Ubuntu 14.10 Utopic Unicorn to Compile Android ROMs

— If you would rather use 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 world-famous guide for setting up a build environment to compile Android ROMs. The aim of this guide is to simplify the configuration process for you.

Follow the directions step-by-step. All you have to do is copy and paste the code sections in order and you will be up and running in no time!

This guide applies to all variations of Ubuntu 14.10 Utopic Unicorn 64 bit. Do not use the 32 Bit version.

Also, PAY CLOSE ATTENTION when to use “sudo” and when to not. It can make things funky if you do something as root that you shouldn’t.

Much thanks goes out to Google, ProTekk, Canonical, and everyone else that I read a random paragraph here and snippet there.

Ready to begin? Ok.

1) Unless it’s a completely fresh Ubuntu installation, many of you have the wrong version of Java 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 purge openjdk-* icedtea-* icedtea6-*

If necessary, follow the on-screen instructions to remove OpenJDK. Otherwise, move on to the next step.

2) Copy and paste the following into the terminal:

sudo add-apt-repository ppa:webupd8team/java

This will add the correct PPA to your system for updated builds of Java 7 JDK.

3) Now you need to install the package. More copy-paste:

sudo apt-get update && sudo apt-get install oracle-java7-installer

Follow the on-screen instructions. You must accept the Licensing Agreement to complete the install.

Press Enter to acknowledge the “OK”, then tab over to “Yes” and press Enter again to accept the license. The installation will continue automatically.

4) Let’s make sure the correct version of Java is activated. Run the terminal command:

java -version

You should see something like:

java version “1.7.0_xx”
Java(TM) SE Runtime Environment (build 1.7.0_xx-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

5) Back to a fresh terminal prompt. Install the main build tools with this command:

sudo apt-get install git gnupg ccache lzop flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z1-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc libreadline6-dev lib32readline-gplv2-dev libncurses5-dev bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev squashfs-tools pngcrush schedtool dpkg-dev

6) When those are done installing, run the next line in your terminal window:

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

That’s it on the package side of things. You guessed it, time for more Terminal. This really is the easiest way, I promise.

7) A program called “repo” lets you communicate with git servers and download all that precious source code. The next command will install it:

mkdir ~/bin && curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo && chmod a+x ~/bin/repo

8) Use your favorite text editor to open ~/.bashrc – I like nano:

sudo nano ~/.bashrc

9) At the very bottom (use the Page Down key) paste this code to a new (empty) line:

export PATH=~/bin:$PATH

10) Save it. In nano that would be Ctrl-O and then Enter. Then Ctrl-X to exit back to a prompt. Restart bash:

source ~/.bashrc

11) In the terminal, navigate to where you would like to download the Android source code. The commands below will make it in your home folder, but if you have limited space you may want to create it somewhere else. Faster is better, i.e. SSD would be best, USB external (even 3.0) will be comparatively slow. Here we go:

mkdir ~/android
cd ~/android

12) Now you’re going to initialize the repo. This is where you decide the flavor of Android you want to build, i.e. AOKP, CyanogenMod, AOSP etc.

For the purposes of the tutorial, here’s the command for SimpleAOSP Lollipop:

repo init -u https://github.com/SimpleAOSP-Lollipop/platform_manifest.git -b L

13) Almost there. Last step, it’s a doozy. Time to get the source. Prepare yourself, many gigs of downloading await.

Don’t worry, it’s automated.

Hey everyone, it’s the final terminal command:

repo sync

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

That should be everything. Now you’re ready to build Android the right way. Good luck!

If you like my project, feel free to buy me a coconut water (donate). It would be greatly appreciated!

8 comments

    1. As of Android Lollipop, Google recommended a switch to using OpenJDK7. So you will need to use the appropriate JDK depending on which version of Android you’re building. Gingerbread-Kitkat = JDK6, Lollipop+ = JDK7

      Good luck with your projects!

  1. Hello Nathan
    thank you for such a simplified tutorial. Am actually trying Builduntu 1.4, its more easier. after all the set up i got confused and i came here to follow the rest.
    i was wondering if it was necessary to setup ccache ? i read it reduce 40% of build time.
    Anyway just dropping by to say hi and thanks.
    with regards
    S03iT

    1. Hi!

      I’ve debated enabling it by default, but with the way disk space is allocated dynamically I’m not sure CCACHE would bring huge performance gains in the case of a virtual machine. BuilduntuVM is meant to run on as many different types of system as possible, with users even making it a portable distro and compiling directly from a USB drive. While this adds considerable time, it works nonetheless. Depending on the resources dedicated to the process, build times may vary from as little as 30 minutes on a dedicated monster box (Xeon, SSD, RAM forever, etc) – all the way past 8+ hours on an old computer.

      If you get a chance to test it, let everyone know what you think. Any solid performance numbers (ie build time comparison) would be awesome. The results would be interesting to learn.

      I’m working on a new version of Builduntu as we speak. The project will be updated here first, stay posted. Thanks for all the support!

  2. Hey.

    So I ended up doing the repo sync straight into the /home/android folder by accident and the whole thing downloaded, but I’d like to move it to my liquidsmooth folder for the rom.
    Can you just move it and resync it without taking forever again ?

    1. this one, I’m not 100% sure but in theory it should work.

      you will have to move all of the newly created data directories, and also the hidden folder with the metadata for the git sync.

      view hidden files and look for a folder called (i think) “.git” but you might want to double check me on that one. give it a shot! good luck!

    2. You should use the –reference flag of repo init to indicate to repo that you already have a local repository that it can take information from, instead of downloading everything from Internet again:

      repo init –reference=~/android -u git://github.com/LiquidSmooth/android.git -b lollipop

Leave a Reply to Abdullah Cancel 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.