Initializing the Build Environment

So you want to develop for Vanir:

Step 1: install 64-bit linux

You MUST have 64-bit linux and at least 4 GB ram. You may be able to build with less but you will have a serious amount of swap which will slow you down hellishly. If you’re interested in speeding up your build time consider buying an SSD, then CPU, then more RAM. an SSD will speed up your process 10x, especially with ccache. I suggest installing the most recent version of either Ubuntu or Mint. You’re on your own for this step.

preliminary linux users:
part 1: make sure you’ve set up your computer and familiarized yourself with basic linux commands such as navigating the terminal, copying files, sudo, rm, ls, diff, apt-get, update-alternative, gedit and other basic useful commands. you may want to make yourself a cheatsheet as your desktop wallpaper until you get used to it if you’re new

part 2: before you install anything, you will want to run a few commands that will align your version of linux with the latest repositories and kernel updates available to unbuntu.

sudo apt-get update
sudo apt-get upgrade

Step 2: Oracle Java SE JDK version 6.XX

The build environment:
The first part of setting up a build environment is installing the correct java package. with ubuntu/mint openJDK is included and the android build process set this as incompatible. I modified our build process to except building with openJDK which would be acceptable for testing purposes only but not for publishing anything.

You will need oracle JDK 6. get the latest version here:
scroll down to java SE 6 update ___ fill in the blank for latest.
download the latest 64-bit version for ubuntu.

run these commands to install:
(notice 6uXX and 1.6.0_XX means 6u37 or 1.6.0_37 if that’s the version you downloaded)

sudo chmod a+x ~/Downloads/jdk-6uXX-linux-x64.bin
sudo cp ~/Downloads/jdk-6u30-linux-x64.bin /usr/lib
cd /usr/lib
sudo ./jdk-6uXX-linux-x64.bin
sudo mv /usr/lib/jdk1.6.0_XX/ /usr/lib/jvm/

now it’s time to “switch” to oracle java:
run this command and see how many other versions of java are available for use. you will want to take note of the number on the left. reenter the number that is in use for now.

sudo update-alternatives ––config java

run this command and input one number greater than what was available in the previous command at the end of the string. you will need to change the XX again to the version number you downloaded. notice i have placed a 2 at the end becuase open JDK was already installed.

cd into /usr/lib/jvm/jdk1.6.0_XX (the one you just installed)
sudo update-alternatives ––install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_XX/jre/bin/java 2

Create symbolic links for the new java files (again XX is your downloaded version)

cd /usr/bin
sudo ln -s /usr/lib/jvm/jdk1.6.0_XX/bin/javac
sudo ln -s /usr/lib/jvm/jdk1.6.0_XX/bin/jar
sudo ln -s /usr/lib/jvm/jdk1.6.0_XX/bin/javadoc

If you run into problems with the symbolic links already being here you can just delete them and run the commands to recreate them

Step 3: GCC-Linaro compiler 4.7.2 – *note* this does not mean it’s a “Linaro” build. I’m including this step in the advent we start using more forward tool chains.

Type this command to see which version you are running:
gcc -v

if you do not have GCC 4.7.2 (latest at the time of this writing)
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.7
sudo update-alternatives –config gcc

Step 4: Installing necessary packages

sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline-gplv2-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc pngcrush

sudo apt-get install libx11-dev:i386
sudo ln -s /usr/lib/i386-linux-gnu/ /usr/lib/i386-linux-gnu/

Step 5: Configuring ADB access

sudo touch /etc/udev/rules.d/51-android.rules
sudo gedit /etc/udev/rules.d/51-android.rules

copy the following into the empty gedit you’ve just created replacing username with your user name. Mine is PrimeDirective so it looks like <PrimeDirective>.
# 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>” # fastboot protocol on panda (PandaBoard) SUBSYSTEM==”usb”, ATTR{idVendor}==”0451″, ATTR{idProduct}==”d022″, MODE=”0600″, OWNER=”<username>”

Step 6: Installing Android-SDK

download the zipped package from this location:

copy the package to the location of your choice. I suggest in your home folder but please note where you installed it because you will need it later.

mine is in this directory:

now run the SDK so you can download the API you need to build. you can do this via terminal or you can just open a file browser.

Step 7: Enjoy a cold frosty beverage. Ahhhh– Intermission.

Step 8: Installing Repo

cd into your home directory in terminal:
mkdir ~/bin
curl > ~/bin/repo
chmod a+x ~/bin/repo

Step 9: Initializing the manifest/getting the source

cd into the folder that you’d like the source to download to. The sync is huge and will take a long time but if it errors out it will pick up roughly where it left off. Also, you will notice the files don’t appear until after the sync is complete. That is because they go to a magical hidden location first in case you screw up something royally like delete an entire build directory then repo copy’s the files back w/o having to download them all again.

type this command to initialize the Vanir jb 4.2 manifest in your working source directory:

repo init -u git:// -b jb42

this command syncs the source.
repo sync

for subsequent source syncs take a minute in comparison to hours. you should type “repo sync -j32” from this point onwards to make the sync happen faster.

Step 10: Setting up your .BASHRC

cd into your source directory.

gedit ~/.bashrc

this is what mine says.. you can modify your locations and versions accordingly. If you are using ubuntu or a distro that includes a bashrc you can just copy these to the end of the file

export USE_CCACHE=1
alias make_aosp=’time mka CC=gcc-4.7.2 CXX=g++-4.7.2 bacon’
. build/; export USE_CCACHE=1; prebuilts/misc/linux-x86/ccache/ccache -M 25G; return 0

alias syncit=’repo sync -j64′
alias bacon-clean=’commonstuff && lunch vanir_toro-userdebug && make clobber && time mka -j8 bacon’
alias bacon=’commonstuff && lunch vanir_toro-userdebug && time mka -j8 bacon’
alias gcp=’git cherry-pick’

export PATH=$PATH:/media/Storage/code/android-sdk-linux/platform-tools/

Step 11: Build commands

every time you open a new terminal you will have to initialize the build environment. to do that type

. build/

next you have to choose which device and what build type you’d like to make. you can do that by typing the following command and choosing the number of the build you’d like.


To start the build, type

mka bacon -j8

-j8 is the number of threads. to find out what the optimum amount of threads you should use type:

grep -c processor /proc/cpuinfo

all together it looks like this for a vanir_toro-userdebug build.

. build/; lunch 16; mka bacon -j8

Depending on your computer stats it may take upwards of 4-5 hours to complete the first build. Average build time is probably 45 min to an hour. During the build process there are many intermediates that are produced before the apks and drivers that come in the ROM are assembled. These intermediates will stay on your machine and be used for common builds or if changes to the source were made they will be rebuilt as well. You will notice that if you type mka bacon -j8 immediately after you complete a build it will only take a few minutes. if you make a change to the source however, it will have to recompile all the stuff involved. If you run into build errors without making any local changes to source then you should run the command “mka clobber”. this will wipe out all the built intermediates that may be broken and causing problems. You should be aware this will take a long time to build again. If you ever publish or share anything, you should clobber your build directory and also wipe your ccache as well. to do this, type “ccache -c -C” in the terminal.

next [TUT] making cherry-picks