I have been meaning to compile Android and get it running on my HTC Magic device ever since I got the phone. I finally got around to actually doing this now so here are some notes I made on the way. My primary concern was obviously that I didn't turn my phone into an expensive brick - but avoiding attempting to flash the SPL should prevent that. The second concern was that I should be able to revert back to exactly what firmware I had before I started to mess about. I can confirm that Nandroid lets you do exactly that.

When I originally attempted to build Android I just followed the instructions provided by Google but this is just a basic build the generic image and you need a kernel customised for the device hardware. You can get this but it is much easier to just go with CyanogenMod as this is reasonably close to generic AOSP but with various fixes and improvements.

Fetch the source, configure and build

mkdir /opt/src/droid
cd /opt/src/droid
repo init -u git://github.com/cyanogen/android.git -b eclair
repo sync
# go and drink a couple of pots of coffee
source build/envsetup.sh 
make -j4 adb
lunch cyanogen_dream_sapphire-eng

# make sure your phone is connected via USB
cd vendor/htc/dream_sapphire
./extract-files.sh
cd ../../cyanogen
./extract-htc-keyboard.sh ;# (failed for me running cyanogenmod)
./extract-google-files.sh ;# (missed a few that dont exist on sapphire)

cd /opt/src/droid
make -j4 droid otapackage ;# takes 1.5 to 2 hours for me

At this point you can test this build in the emulator by just typing emulator. The emulator loads the firmware files from your build output directory (defined in ANDROID_PRODUCT_OUT)

Build the update.zip file

To make a CyanogenMod update.zip package:

  • ensure you have already installed pngcrush
  • ensure you have already installed squashfs-tools
cd /opt/src/droid
source build/envsetup.sh
lunch cyanogen_dream_sapphire-eng
TARGET_NO_RADIOIMAGE=true make -j4 droid otapackage
vendor/cyanogen/tools/squisher

This creates an update-cm-VERSION-LOGNAME.zip file that can be flashed. Copy the update file to the sdcard, boot to the AmonRA recovery shell and flash the newly built zip. From CM5.0.7 you don't need to wipe. The first boot is a bit slow as it regenerates the cached dalvik code from new set of APK files.

I had some trouble making an OTA update package the first few times. I eventually worked out that I needed to have the squashfs-tools installed or else you must define NO_SQUASHFS before running the squisher script. Without either of these the system image was missing the xbin/ directory and would hang up on booting.