Thursday, October 27, 2011

Welcome, Android! Compile AOSP Android 2.3.7 From Source on Ubuntu 11.10 (64bit).

Ubuntu 11.10 (64 bit), a internet connection & if your building for a phone.. The phone.

Fire up a terminal, and download the following packages to start with:
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev g++-multilib lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline-gplv2-dev lib32z1-dev libgl1-mesa-dev
Now make sure your using the right version of Java:
sudo add-apt-repository ppa:ferramroberto/java sudo apt-get update sudo apt-get install sun-java6-jdk sun-java6-plugin
Note: this is a personal PPA, if you don’t trust these, you can download Java from Oracle. Now, switch to the correct version of Java:
sudo update-alternatives --config java
Make sure you select:
To make sure you have the correct version of Java do this:
java -version
It should show:
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

You just downloaded all the software needed to build Android. Make sure that your Ubuntu machine can use your USB devices by creating /etc/udev/rules.d/51-android.rules (as root user) paste the following inside that file:
# adb protocol on passion (Nexus One) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="" # fastboot protocol on passion (Nexus One) SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="" # adb protocol on crespo (Nexus S) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="" # fastboot protocol on crespo (Nexus S) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER=""
Please make sure to switch “” to the username of your Ubuntu user.
Make the file Executable:
sudo chmod +x /etc/udev/rules.d/51-android.rules
And restart udev:
sudo /etc/init.d/udev restart
Now it’s time to download the repo and stuff like that. In the same terminal type:
mkdir ~/bin curl > ~/bin/repo sudo chmod +x ~/bin/repo 
Now open up your bashrc (nano ~/.bashrc) and add the following to the end:
Save the file and source it:
source ~/.bashrc
GETTING THE SOURCE: Now, make a directory where you would like to build Android. I always keep my system clean so i made a Android/source/Gingerbread folder:
mkdir -p ~/Android/source/Gingerbread
Now go to that directory:
cd ~/Android/source/Gingerbread
Now let the repository initialize:
repo init -u -b android-2.3.7_r1
And next sync it. This will take a while :
repo sync
You now have the source code of Gingerbread on your Ubuntu machine. Sweet! Of course, you still have to build it. 

First I will explain how to build a normal generic build. This is a non phone specific build. In the Android source folder type:
. build/
This will prepare your build environment. This is needed to have tools like lunch, mmm and other nifty Android specific tools. Now it’s time to actually choose our version of 2.3.7:
You will be asked which Android version you want, choose “generic”. Ubuntu 11.10 introduced some issues when building Android. We have to fix/resolve them first. In the core folder of your Android source, open up the following file:
vim frameworks/base/libs/utils/
And change the following line:
Next open up:
vim build/core/combo/
And change:
Now! It’s time for the real deal, building the source. It’s time to fire up make:
make -j4
Do note that there are diffrent -j parameters of make to build faster. You could use make -j4 if you have 2 cores, and make -j8 if you have 4. This will speed up the building. If the building ends with something like system.img that the build went ok. Congratulations you’ve just build Android 2.3.7. You can flash it to your phone with fastboot. But this is just a generic build missing device specific features.

Connect your phone to your PC, and make sure that it’s on debugging mode. From the root of your source, go to the Passion (code name for Nexus One) specific folder:
cd device/htc/passion
Import all the needed files:
If this ends with no errors your done, you can now return to the root of your source tree. If you followed this how to go back to:
Now use lunch to choose the passion-full-userdebug build.
And! Now you can use make to build Android:
make -j4
If your build ends with something like this: Install system fs image: out/target/product/passion/system.img The build is complete. You can again use fastboot to flash it to your device. You now have the full open source version of Android running on your phone. If you have any questions about this topic please don’t hesitate to ask them in the comments i’ll do my best to give answers when possible.


Thanks alot for this...
helped me alot..
Good blog...

Welcome buddy!
And Thanks, keep visiting... :)

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More