— If you would rather use a ready-to-go Virtual Machine based on these instructions, check out my post here! —
With a new version of Ubuntu comes an update to my world-famous guide for setting up a build environment to compile Android ROMs. 14.04 Trusty Tahr is the next Long Term Support edition of the popular Linux distro. 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.04 LTS Trusty Tahr 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 6 JDK that are compatible with 14.04.
3) Now you need to install the package. More copy-paste:
sudo apt-get update && sudo apt-get install oracle-java6-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:
You should see something like:
java version “1.6.0_45”
Java(TM) SE Runtime Environment (build 1.6.0_45-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 libglapi-mesa:i386 libgl1-mesa-dri:i386 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:
10) Save it. In nano that would be Ctrl-O and then Enter. Then Ctrl-X to exit back to a prompt. Restart bash:
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 is basically unusable. 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 AOKP KitKat:
repo init -u git://github.com/AOKP/platform_manifest.git -b kitkat
13) Almost there. Last step, it’s a doozy. Time to get the source. Prepare yourself, 10+ GB of downloading await.
Don’t worry, it’s automated. Go to sleep. Eat something. Perhaps you have heard of this new thing the kids are doing called “going outside”? Yeah, I didn’t think so. Me neither.
Hey everyone, it’s the final terminal command:
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!
Thanks for your early update for 14.04
I want to ask why you installing :i386 version of packages like (zlib1g-dev:i386 libx11-dev:i386 libreadline6-dev:i386) i didnt install any i386 package and it still works
thanks for your reply in advance
This is designed to compile for as many devices as possible. It’s based on Google’s official documentation, and certain things required for different flavors of Android (CM vs AOSP vs AOKP) and various device manufactureres.
If it works for you, cool. *shrug* As long as you’re sure. Sometimes parts of the build won’t process correctly but you’ll still get a usable file. It might just not be optimized (as with a tool like pngcrush). I dunno.
Thanks for your reply and appriciated your hard work
Just wanted you to know this is 100% money. Thanks for taking the time to post.
do i have to install i386 packages?
What would be the command if I wanted to tuse AOSP repo? Thank you! This is great!
If you want to use the master branch, the command would be:
repo init -u https://android.googlesource.com/platform/manifest
That will prepare the directory to mirror the source. Then to begin the download:
This will take a while. But on the plus side, any time you need to update (to reflect the latest code changes) all you have to do is repo sync and it will only need to download the files that have changed, not everything.
How about a complete guide for AOSP with no mention of CM or AOKP so it’s easier to copy and paste
Thanks for the suggestion! I’m working on a guide for compiling, just super busy with school and work and life. I’ll post it soon – stay tuned.
I have only need an extra this package to overcome switch pm error
not sure this is general or just my problem but just wanna say that
thanks for your helps and congrats for your new site 🙂
i found this post today as i was preparing to install ubuntu 14.04.1 in my vaio. i have a decent laptop so am thinking to use as dual boot. my perception about VM could be wrong as i think it wont be able to use the machine to its full potential.
i tried your builduntu in VM but i could not compile slimrom. they have poor support and less tutorial. it is not your product fault, neither theirs, i just got lost and could not find answer. so am thinking to start fresh. i hope i can make it this time in 2015 😛 😉