Building android from source for nexus 4
Iv recently been playing with building my own android rom for my nexus 4. So i figured id lay it out in a nice easy to read format.
Firstly, This wont go through rooting the N4 and install CMW as its pretty basic, but ill write it up elsewhere for those looking.
Secondly, im doing this on ubuntu 12.10 64bit. For all the latest (since froyo i think) android builds you have to use 64bit operating systems.
Thirdly, windows is NOT supported. So if you dont have an ubuntu machine to hand, then try using a virtual machine in virtualbox.
Fourthly, Compiling takes ages! Im doing this on an 8 core machine, it takes about an hour. Iv run it on a quad atom server, it took 4-5 hours.
Now thats sorted, lets begin.
We need to prepare our build enviroment. Firstly we need to install the java6 JDK. Due to licensing issues, the java6 jdk isnt in the ubuntu repos, so to install it we have to add additional repos-
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java6-installer
You will need to accept the licensing, then that will be installed.
Now we need to install everything needed to build android –
sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
So, thats the build enviroment ready, lets pull the sources.
Make sure you have a bin/ directory in your home directory, and that it is included in your path-
Download the Repo script and ensure it is executable-
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
Next we need to create our working directory-
Now to bring in the latest verion of Repo-
repo init -u https://android.googlesource.com/platform/manifest
Now we actually pull in the sources *note* this can take a long time, depending on your boradband speed, i believe the sources end up being about 8GB-
….after that long wait, we need to add the proprietary binaries..or drivers, for your device. As this guide is for the N4 then we are downloading the “mako” binaries, these are available here : https://developers.google.com/android/nexus/drivers#mako
Just download the 3 available binaries and extract each one. After you have extracted them, you are left with 3 shell scripts.
Move these 3 shell scripts to your working directory (~/android) and run them…you will have to accept licenses for each one.
Once that is done, we are ready to actually build android.
issue the following command to prepare your build environment-
Now we need to select the device we are building android for, so type-
And as this is the N4 we are building for (mako), i type 11.
All thats left now is to start the build process.
Make is able to process jobs in parallel on devices with multiple cores, using the “j” switch. It is usually set to twice the number of cores available on the CPU. So for me i use –
make -j16 otapackage
The otapackage option is to leave us with a CWM flashable zip.
After the long build time, this leaves us a flashable zip in
Any problems, give me a shout.
After i flashed my build, my phone wouldnt connect to the internet, i think it was just APN details not being valid, but i havnt had time to fix it yet.