Building Android on Ubuntu 14.04

Install Ubuntu 14.04 and configure the required packages

# update packages
sudo apt-get update -y

# install Java
sudo apt-get install openjdk-7-jdk

# cleanup
sudo apt-get autoremove -y
sudo apt-get update -y
sudo apt-get dist-upgrade -y
sudo dpkg --configure -a

# install deps
#  https://code.google.com/p/android/issues/detail?id=178284
sudo apt-get install -y g++-multilib
sudo apt-get install -y bison g++-multilib git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip
# I can't live without vim. My muscles are pre-programmed...
sudo apt-get install -y vim

Turn on optimizations

echo 'export USE_CCACHE=1' >> ~/.profile

Setup usb access

sudo vim /etc/udev/rules.d/51-android.rules:

# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"
# fastboot protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"
# adb protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"
# adb protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"
# adb protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"
# adb protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="<username>"
# fastboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"
# usbboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>"
# usbboot protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"
# adb protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="<username>"
# fastboot protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="<username>"
# adb protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="<username>"
# fastboot protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="<username>"

Get the repo tool

mkdir ~/bin
PATH=~/bin:$PATH
#Download the Repo tool and ensure that it is executable:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

Setup our working directory

mkdir -p ~/src/android
cd ~/src/android

Set your identity

git config --global user.email "[email protected]"
git config --global user.name "nathan"

Repo init

repo init -u https://android.googlesource.com/platform/manifest

Pick a branch, I'm getting the latest for my Nexus 7

# Nexus 7 (Wi-Fi) | nakasi (grouper) | full_grouper-userdebug
repo init -u https://android.googlesource.com/platform/manifest -b android-5.1.1_r1

or for the Nexus 5:

repo init -u https://android.googlesource.com/platform/manifest -b android-5.1.1_r3

Get the code

repo sync -j 4

Get the binary drivers

mkdir -p ~/src/android-binaries
cd ~/src/android-binaries

Nexus 7

wget https://dl.google.com/dl/android/aosp/asus-grouper-lmy47v-f395a331.tgz
wget https://dl.google.com/dl/android/aosp/broadcom-grouper-lmy47v-5671ab27.tgz
wget https://dl.google.com/dl/android/aosp/elan-grouper-lmy47v-6a10e8f3.tgz
wget https://dl.google.com/dl/android/aosp/invensense-grouper-lmy47v-ccd43018.tgz
wget https://dl.google.com/dl/android/aosp/nvidia-grouper-lmy47v-c9005750.tgz
wget https://dl.google.com/dl/android/aosp/nxp-grouper-lmy47v-18820f9b.tgz
wget https://dl.google.com/dl/android/aosp/widevine-grouper-lmy47v-e570494f.tgz

or for the Nexus 5

wget https://dl.google.com/dl/android/aosp/broadcom-hammerhead-lmy48b-2d0a908d.tgz
wget https://dl.google.com/dl/android/aosp/lge-hammerhead-lmy48b-92cca4b9.tgz
wget https://dl.google.com/dl/android/aosp/qcom-hammerhead-lmy48b-021b52eb.tgz

Extract everything

for a in `ls -1 *.tgz`; do tar xf $a; done

Each tgz will extract an installer script (*.sh), install each of these

for a in `ls -1 *.sh`; do bash $a; done

Put the vendor dir where it goes:

mv vendor ../android/

Set the cache size

prebuilts/misc/linux-x86/ccache/ccache -M 50G

Build

# setup
source build/envsetup.sh

# choose a target
lunch full_grouper-eng
# does this work?
#lunch asop_grouper-eng

# build it!
make -j4