--- Copied with permission from http://nathanpfry.com ---
TLDR; if you don't care about an explanation of what your system is doing,
click here to check out XDA Senior Member Aaahh's sweet two-step method based on my guide below.
Otherwise, keep reading!
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 may 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-\*
It's time to install Java, one of the core pieces for compiling Android ROMs. Depending on which version of Android you are building, you will need the corresponding version of the Java Development Kit.
*** IF YOU ARE BUILDING ANDROID GINGERBREAD THRU KITKAT (2.3 - 4.4.x) USE THESE INSTRUCTIONS FOR JDK 6***
sudo add-apt-repository ppa:webupd8team/java
3) Now you need to install the package. More copy-paste:
sudo apt-get update && sudo apt-get install oracle-java6-installer
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 "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)
Continue to Step 5.
*** IF YOU ARE BUILDING ANDROID L AND ABOVE (CURRENT AOSP MASTER BRANCH) USE THESE INSTRUCTIONS FOR JDK 7***
sudo apt-get update && sudo apt-get install openjdk-7-jdk
3) Let's make sure the correct version of Java is activated. Run the terminal command:
Continue on to Step 5.
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
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
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
sudo nano ~/.bashrc
mkdir ~/android cd ~/android
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
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:
That should be everything. Now you're ready to build Android the right way. Good luck!
Please hit the "Thanks" button if this post helped you out!