Pages

Tuesday, December 18, 2012

Compiling Android Source Code Froyo (2.2) on Ubuntu 10.04



A few days back, one of my friends gave me compiled version of Android Froyo (2.2) source code. And without compiling it myself, I just used it as it is for my purpose. And after reading some installation guides on the internet, I thought, I should write a tutorial on it so that me and others can benefit from it.

But it turned out to be a bad decision by putting a tutorial without even testing it. I feel sorry for others too. I tried to compile the same compiled source code again, it began to show me a lot of errors. So without going into what stupid things happened to me,  I would highly recommend you to install Ubuntu 10.04 as this was the only version which worked for me. And the reason is Ubuntu 12.04 and Ubuntu 12.10 had gcc versions which were higher than the required version for compiling Froyo (2.2). And I didn't know if cross-compiling for GCC versions was possible or not, I just installed Ubuntu 10.04.

One more thing, if you have Thinkpad T420 or any latest product, Ubuntu 10.04 was released before these products. So even if you install it successfully, you might not be able to view the screen text due to lack of audio/visual drivers.That's what happened to me, so I ended up installing it on Virtualbox.

Anyway, here is the recipe.
 
Step 1:

Install Ubuntu 10.04 either dual boot or as a virtual machine on Virtualbox. If you are using Virtualbox, reserve 2 GB of memory for the virtual machine. It gave me error for 512 MB.

Step 2:

If you don't want to go into the hassle, I have shared android source code through my GoogleDrive Account here. It's around 2 GB in compressed format.

else Download the Android source code from google source code.. I downloaded source code for Froyo which had size of around 6 GB. Make sure, you have curl installed.

Run following commands:

$ mkdir ~/bin

$ PATH=~/bin:$PATH

$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo $ chmod a+x ~/bin/repo

$ mkdir android

$ cd android

$ repo init -u https://android.googlesource.com/platform/manifest -b android-2.2.2_r1

$ repo sync


Step 3:

$ sudo -i

Type your login password and then, you wont have to type 'sudo' on later stages.

Step 4:

$ add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ apt-get update

Step 5:


Install Java-5.

$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy main multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk

Step 6:

Install git with:

$ apt-get install git-core

If you are running OS other than Ubuntu, find your command here.

Step 7:

Install the required dependencies. It's one command. Note that plugin list on AOSP site is not correct.

$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib64ncurses5-dev \
x11proto-core-dev libx11-dev lib64readline5-dev lib64z-dev \
libgl1-mesa-dev g++-multilib tofrodos

Step 8:

Run following commands to set path variables and compiling your android source code. Compilation may take a few hours depending on your system specifications.

Assuming you are in /home/mohsin directory and your downloaded and unzipped code is in this directory such that /home/mohsin/android/out is a valid directory.

$ cd android
$ source build/envsetup.sh
$ lunch full-eng
$ make -j4

Setup the environment variables:

$ export ANDROID_PRODUCT_OUT=/home/<userName>/android/out/target/product/generic

$ export PATH=$PATH:/home/<userName>/android/out/host/linux-x86/bin

Restart the terminal.

Step 9:

After completion of step 8, lets check if it was compiled successfully.
Run following command.

$ emulator

If you see something like "No command found 'emulator'. Did you mean Qemu" etc., that does not mean, it was not successful.

I have a temporary fix right now. It will work only on currently working terminal like every time, you open a new terminal, you need to run these commands before running 'emulator' command.

Temp Fix#1:

$ source build/envsetup.sh
$ setpaths

Temp Fix#2:

$ source build/envsetup.sh
$ set_stuff_for_environment

Now run $emulator and it should open an emulator.

If it works, we are done for the part of compiling Android Source Code which have been a pain in the ass for me for a few days.



No comments:

Post a Comment