Android OS Source Code Modification (Part-II): Making the System

Considering that you have followed all the instructions in my previous post here, I take this series of post forward which illustrates how to compile the source code in order to get it running in an emulator.

Building Android 2.2 source to run an Emulator

The main reason for first doing this instead of illustrating the modification of source is that, you should know what steps you have to perform in order to see the changes that you have made.
Secondly, you must be aware of outcomes of your modification.
Third, You must know what your objective is, then you'll be able to work more precisely, for example, you now know that you have to run your modifications in an emulator, so you'll see the screens, change them, make the build and will again run the emulator to see the changes.
Moreover, I feel that it will help you understand what actually happens when we build for a system, as a result, you'll be able to make changes more comfortably, and without working vaguely .

So, I have just ended up creating an emulator, and there's really nothing big involved in this.

To start the compiling/building/making process, we just use the make command.
And to make it deliver an emulator, we use the sdk switch with make command.
This is done in the following manner:

In a shell prompt, first go to the directory where your files are (probably under 'bin' or 'mydroid') or you can also set the $PATH to have any of these folders in your path, then run:

$ make sdk

The above lines will compile the source and will generate an sdk folder under your root directory (most probably this root directory will be 'bin')
If your build fails due to a missing run-java-tool then run the following command to simple set your environment variable ANDROID_JAVA_HOME:

$ export ANDROID_JAVA_HOME=$JAVA_HOME

Then again start the build process with the make sdk

Now wait for a long time, as it is going to take long for it to compile the code.
on my machine, it took 5 hours.

When it finishes, you should be able to find one sdk folder under following directories:

~/bin/out/host/[OS build]/sdk

in my case, the [OS build] folder was linux-x86, so just replace it with yours.
under normal circumstances, it should be yours too.

This folder will have the emulator which you can run.
This emulator can be found in:

~/bin/out/host/[OS build]/sdk/[sdk version dependant folder]/tools 

here [OS build] was linux-x86 on my system
and [sdk version dependant folder] was android-sdk_eng.root_linux-x86.

To run the emulator that you have just built, you'll run the emulator command from a terminal, but before that, you must have an AVD to run the emulator.

So,to create an AVD, run the following commands under a terminal

$ cd /bin/out/host/[OS build]/sdk/[sdk version dependant folder]/tools
$ ./android create avd -n [Your AVD's name] -t 1 

here [Your AVD's name] is whatever you want your AVD to be named like

As a result, you might get something like this-

Android AOSP (Preview) is a basic Android platform.
Do you wish to create a custom hardware profile [no]no
Created AVD '[Your AVD's name]' based on Android AOSP (Preview),
with the following hardware config:
hw.lcd.density=160

Now, to run the emulator with this AVD, run the following command:


~/bin/out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86/tools$ ./emulator @[Your AVD's name]

You should get your Emulator running.

In the next post, I might show how to make changes in few things of the source, and how to build an emulator to see those changes.

Enjoy!

Android OS Source Code Modification: Getting Started with Android Source Code modification

I have just started playing with Android OS Source and I can assure you, it can be a real pain for some people, so be prepared.

For all the downloading and documentation needs, you can go to: source.android.com

We'll be using one key command , repo, to download the OS from the Git repository.
be patient and read the full article, it will explain all.

First of all, you can't play with it on your beloved Windows (to be specific, Android 2.2 Source Code development doesn't support Windows) . you'll have to get a Linux (preferably Ubuntu, as they've used Ubuntu) to work with the source of Android 2.2.

Second, Not all the things written in the documentation are correct. I cam across many anomalies in the documentation, sometimes total contradictions too, so I'll be discussing the real details too.

To download the source code, you'll have to go to this link to get the instructions (While I am also giving them here) -> http://source.android.com/source/index.html

Steps to setup developer machine:
  1. You should have a Mac or Ubuntu machine, as Windows is not yet supported. Now here's the catch, the documentation says they haven't tested 64 bit versions of Ubuntu and prefer to have feedbacks, but the reality is, if you are going to work with Android 2.2 or higher, you wouldn't be able to build your source if you aren't running a 64 bit version. so better get the 64 bit version of Ubuntu and follow the steps ahead. and please, do get a hi end system with at least 3 GB of RAM, good 64-bit processor-motherboard and nice HDD space, as while development and building, Android OS becomes a monster in every aspect.

  2. As soon as you finish setting up your Ubuntu 64, you'll have to setup some more things. use this command to get them:

    $ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl sun-java5-jdk zlib1g-dev  gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev

    Notice here, there are a lot of packages being installed, but perhaps you won't be able to install sun-java5-jdk  as its not available in Ubuntu repository. You'll have to install it via Sun's website. AND it will also not be supported, as Android 2.2 will require Java6. don't go by the documentation for this. this is why i have written it in strike-through.

  3. Now, install Java6. to ask how this will be done, ask me separately or google for it, as this article isn't about it.

  4. Repo & Git: Repo is a client that fetches the source of Android OS from the git repository. Google guys maintain the code of Android on git, and its updated frequently, so now you'll have to setup repo and fetch the source code.
 Configuring Repo:
  1. To download repo, you'll have to follow some easy steps, follow these lines:
    
    $ cd ~
    $ mkdir bin 
    $ echo $PATH 

    The last line checks if ~/bin is in your path.
    Now to download repo:

    
    $ curl http://android.git.kernel.org/repo >~/bin/repo
    $ chmod a+x ~/bin/repo

    This will download the repo script and will make it executable.

  2. now the next step is to fetch the whole Android code. hold your breath, its of about 2.1 GB, and will take a LONG time! run this command:

    $ ./repo init -u git://android.git.kernel.org/platform/manifest.git

    Notice that the documentation doesn't include a './' before repo in this command, but you'll have to include it in order to run it. this will download the manifest and will set the repo client up, so that when you sync, it downloads the correct thing. It will ask for your name and email, so give it. better if its a Google account, it can be used to submit back the code. The next command will start download:

    $ ./repo sync

    this command will start syncing your current directory (that is ~/bin) with the Android 2.2 git repository. As this process is going to take time, you can go out for a walk or a game.

  3. Every time you run the syncing, it will sync your base code with the code available in the repository, so possible upgrades will happen. It will be good if you follow a good backup policy.

  4. When you're back, the Android OS might have got downloaded by then, and you can begin experimentation with it.

That's it for now. In my next post I'll explain how to setup Eclipse for Android Source modification and how to build the whole OS.

Till then, take care.
and, I love your comments, so go ahead!