Sometimes it helps a lot to know what’s going on inside those not well documented APIs. And the open source nature of Android encourages people to learn from the source code.However, as of now, source code dose not come out of box in eclipse ADT. Fortunately, it’s not so hard to make it work. You do not need to build the entire android
Method 1: (For Android 4.0/SDK 14 or above)
Google includes Android SDK source code for SDK 14 or above, but we need some set up.
Download the source.
- Select “Source for Android SDK” and click install packages
Attach the source code to android.jar
- Right click on android.java, and select properties. You should see the following dialog to set Java Source Attachment

- Click external folder, select {Android_SDK_Root}/sources/android-{SDK-version}. For example, if Android SDK is installed in /opt/android-sdk-mac_x86 and we are setting SDK 14 ‘s source, the folder should be /opt/android-sdk-mac_x86/sources/android-14
Method 2 (For Android SDK below 14)
However, most of us need to support lower version of Android device. But we can take a similar approach .
Get the source code
Follow source.android.com to download android source code. Build is NOT required
Decide the SDK version
See http://source.android.com/source/build-numbers.html for a complete list of SDK release, then switch to the needed version
For example, to support android 2.2, we first get android 2.2 source code
$ repo init -b master -m base-for-3.0-gpl.xml
$ repo sync
$ repo forall -c git checkout android-2.2.3_r2
Copy corresponding source folders
mkdir -p {Android_SDK_Root}/sources/android-8
cp -r frameworks/base/core/java/android/ {Android_SDK_Root}/sources/android-8/android
We can do similar thing for java and javax packages.
Then select the source attachment folder the same way.
Use cp instead of ln -s so we can save the snapshot and checkout other version as well



