Viewing Android Source Code in Eclipse

When developing for and learning about Android, having the source code is a great tool! Checking out the code is covered by the Get Android Source Code document at source.android.com and is done with something like the below snippet:

Now for Eclipse to find the source, you need to modify the SDK installation. The folder structure of the Android SDK looks something like:

android-sdk/
	SDK Readme.txt
	add-ons/
	docs/
	platforms/
		android-4/
		android-7/
		android-8/
	samples/
	tools/

The Android Development Tools plugin for Eclipse looks for a sources folder in a platform, so java source code should be placed as in $SDK_DIR/platforms/android-8/sources/java/lang/String.java. The below python script, inspired by an earlier script by Michael Forster, extracts java source code files from a checkout and puts symlinks to them in the required sources folder:

After running the above script for an Android platform, you should hit Refresh in Eclipse for a project using the platform:

You should now be able to browse and use the source of the Android platform from inside Eclipse: