Building Android from source, a compiled guide

Recently I got my hands on a Android dev phone 1, the unlocked developer-friendly phone using the shiny new Linux-based OS from Google. I spent a few days to figure out how to compile a new OS into the phone. Unlike the application development process that is well documented by Google, system development is largely left to the community to figure out. I am providing here a step-by-step guide for those who are like me with some inputs of mine but mostly with links to the websites…

First off, you need a system where you can download the android sources from the web and compile. There are several platforms which are supported for the build process – Ubuntu 32 bit, 64bit and Mac OS X. My personal view being 32 bit OS is the best as it requires least modifications. If you have a ubuntu box sitting around you can start-off right away. If not, I suggest using a virtual machine instead of installing an OS. You can install the free vmware player from vmware and use a prebuilt ubuntu 32 bit virtual appliance for compiling Android. Either way, apply all pending security and software updates before setting up the Android development tool chain.

Your starting point for android system development is Android source website. Follow the instructions there to the dot. The “repo sync” or download process should take less than a hour if you are on a good broadband connection. The “make” will take nearly 3 hours on a raw metal machine. On a virtual machine based ubuntu system it might take more time. The compilation will produce 4 img files – boot, userdata, ramdisk, and recovery.

Now, before you flash the binary img files you need to take care of few more details. Follow the dream aka dev phone 1 instructions as we are compiling for the google dev phone 1. In step 5, you may get a error. This is just a path issue. Setup your path and you should be fine. Once you run the repo sync & make again, it will get some updates from the web and build the img files suitable for the dev phone.

Google website doesn’t tell you how to get the img files into the developer phone. You need to use two tools ‘fastboot’ and ‘adb’ to get the images into the phones. They are located in the folder “out/target/product/dream/” relative to the code branch you checked out – either main or cupcake. Add that directory to the path variable. Connect dev phone 1 to the PC and verify through ‘abd devices’ from the terminal. Adb will start a daemon on first run. Some users have reported that they problems identifying the devices. This seems to be mainly the case if you are using a VM. If this is the case, ’sudo’ all your commands. Once you have verified the device is identified by adb, next boot the phone into fastboot mode. For this, switch off your phone and then press and hold both the poweroff+back until you see the 3 Androids on skates and the words “fastboot” in the middle of the screen. Now issue “fastboot devices”. You should be able to see your phone and it should say it is in fastboot model. At this stage, you need to issue the following commands

fastboot flash boot boot.img

fastboot flash userdata userdata.img

fastboot flash system system.img

and finally fastboot reboot and you are done getting a new OS on the phone :)

ps: feel free to drop a comment or question

Category: How-To 2 comments »

2 Responses to “Building Android from source, a compiled guide”

  1. Stefan

    Nice article, I also successfuly build and flashed android last week.
    If you don’t see the words “fastboot” but “serial” in the screen with the skateboarding androids you can push the back button until it says “fastboot”.

  2. Markus

    Thanks Krishnan, very helpful. I just started compiling my own G1 images …

    I encountered an additional problem during step 5 (Building for Dream):

    Problem: adb (invoked by the extract-files.sh script) cannot connect to G1 on Ubuntu 8.04 (newer Ubuntu versions also seem to experience this problem)

    Fix:

    1) ’sudo gedit /etc/udev/rules.d/50-android.rules’

    For Gusty and Hardy, edit the file to read:

    SUBSYSTEM==”usb”, SYSFS{idVendor}==”0bb4″, MODE=”0666″

    For Dapper, edit the file to read:

    SUBSYSTEM==”usb_device”, SYSFS{idVendor}==”0bb4″, MODE=”0666″

    2) ’sudo chmod a+rx /etc/udev/rules.d/50-android.rules’

    3) reconnect G1 via USB

    4) test via ‘adb devices’; your G1 should be listed now

    5) rerun the extract-files.sh script

    Cheers,

    Markus


Leave a Reply



Back to top