I thought I'd have a go at building Android 2.0.1 from source for the HTC Magic (AKA MyTouch 3G and HTC Sapphire). Mine is the 32B board from UK Vodafone - Google branded. Current most recent firmware from HTC for the device is Android 1.6, although Android 2.0.1 source code is available from Google. Android 2.0 roms are already available from xda-developers.com, but I wanted to see how hard it was to do it myself. Also if I'm successful this will be a place where all information will be in one place.
This is not rocket science by the way - this is my experience in following the guides from Google and HTC on Ubuntu 9.10. All of this information is already out there, just not necessarily all in one place in this format or adapted for this environment.
Building on Windows is not supported. I'm using Ubuntu 9.10 (32bit) on my laptop. Java JDK 1.5 is required, using 1.6 is supported but you have to make additional steps changing instances of "1.5" to "1.6" in makefiles. 64bit Ubuntu users may want to follow a different guide, not sure if any differences here could cause a build to fail.
Setting up your environment ready for development, install the following packages (reference):
sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zipcurl libncurses5-dev zlib1g-dev valgrind
In Ubuntu 9.10 you can't get Java 1.5 using apt any more. I downloaded it from java.com and installed it in /usr/local/java/jdk1.5.0. Then:
ln -s /usr/local/java/jdk1.5.0/bin/java /usr/local/bin/java
If you try "java -version" it should tell you "Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)". Finally, edit your ~/.bashrc using vim and add the following to the end of the file:
export JAVA_HOME=/usr/local/java/jdk1.5.0/ export ANDROID_JAVA_HOME=$JAVA_HOME export PATH=$PATH:/home/ben/bin:$JAVA_HOME/bin
Reload your .bashrc file using ". ~./bashrc".
Setting up repo - a Google tool to manage your Android source code repository:
cd ~ mkdir bin curl http://android.git.kernel.org/repo >~/bin/repo chmod a+x ~/bin/repo mkdir mydroid cd mydroid repo init -u git://android.git.kernel.org/platform/manifest.git -b eclair
Answer the questions where prompted and then fetch the source code using:
repo sync
This bit takes a while ... when finished:
gpg --import
Paste in the GPG key at the bottom of this page and then press ctrl+D. Now we need the HTC binaries and kernel source to build specifically for the Sapphire.
wget --referer=http://developer.htc.com/google-io-device.html http://member.america.htc.com/download/RomCode/ADP/signed-google_ion-ota-14721.zip? # line commented -- wget --referer=http://developer.htc.com/ http://member.america.htc.com/download/RomCode/Source_and_Binaries/sapphire.hep-357975db.tar.bz2
Now to do the final bit of setup and start the build (reference here):
cd ~/mydroid/vendor/htc/sapphire-open ./unzip-files.sh cd ~/mydroid . build/envsetup.sh lunch aosp_sapphire_us-eng
Yes that is supposed to say "lunch", not "launch". Now the build can be started! One final thing is required to stop the build from crashing (reference):
cd ~/mydroid/external/webkit git cherry-pick 18342a41ab72e2c21931afaaab6f1b9bdbedb9fa
Now we can start the build:
cd ~/mydroid make -j4
Bah, I've got an error: "Your version is: /bin/bash: javac: command not found.". There's a problem with my path (which I have corrected above already).
export PATH=$PATH:$JAVA_HOME/bin
Now it's building. The HTC website advises this is now a good time to make a cup of tea, or take a nap. I'll revisit this tomorrow I think!

