Print
Android SDK Source Code
"There was nothing you could have done, Luke, had you been there. You'd have been killed too, and the droids would now be in the hands of the Empire."

While the Android SDK comes with a complete set of javadocs, the source code of the SDK is missing in the SDK distribution. This is very unfortunate, since you cannot easily debug into SDK methods (at least not without running into de-compiled code) nor can you see how things actually work.
However, there is a quick fix to that problem. I downloaded the complete Android source including the Linux, drivers, libs, etc., like explained here: http://source.android.com/download and ran my short bash script on the source tree:
#!/bin/sh
#
# Create a source jar with all relevant android java sources.
# Create JavaDoc for all java sources.
# @author Wolf Paulus
# 
export ANDROID_GIT_ROOT="/Users/wolf/Work/mydroid"

# create and / or clear tmp directory 
mkdir ~/tmp 2>/dev/null
cd ~/tmp
rm -R * 2>/dev/null

# copy java sources from git trunk

cd $ANDROID_GIT_ROOT 
cp -R `/opt/local/bin/gfind -wholename */java/android` ~/tmp
cp -R `/opt/local/bin/gfind -wholename */java/dalvik` ~/tmp
cp -R `/opt/local/bin/gfind -wholename */java/java` ~/tmp
cp -R `/opt/local/bin/gfind -wholename */java/javax` ~/tmp
cp -R `/opt/local/bin/gfind -wholename */java/junit` ~/tmp
cp -R `/opt/local/bin/gfind -wholename */java/org` ~/tmp
cp -R `/opt/local/bin/gfind -wholename */java/com` ~/tmp
cp -R `/opt/local/bin/gfind -wholename */awt/java` ~/tmp
#create list with source file names
cd ~/tmp
/opt/local/bin/gfind -wholename */*.java > files.txt 2>/dev/null
jar cvf androidSrc.jar @files.txt

#create doc directory for javadoc
mkdir ./doc
javadoc -J-Xmx512m -d ./doc @files.txt
jar cvf androidDoc.jar -C ./doc ./doc/*

#eof

This will generate an android-2.1-src.jar as well as an android-2.1-javadoc.jar. The android-2.1-javadoc.jar contains all the relevant java sources and after attaching it to the SDK classes in your favorite IDE (IntelliJ in my case) you can easily step into the code, for instance during a debug session...

The android-2.1-javadoc.jar contains the regularly formatted JavaDoc of the Android SDK, in case you have a hard time getting used to that goofy green. Both jars were generated from the head of http://android.git.kernel.org on Jan. 20, 2010.


QR code, to put this blog on your mobile