How to attach source to android.jar

I am new to Android. I am working in the Windows OS with the Eclipse IDE. My simple application has a spinner that populates a list from database column. When I click on the spinner Class, the file Editor says that source not found and the android.jar has no source attachment.

I downloaded the source code and placed it in this location:

android-sdk-windows\platforms\android-8

Then, I attached this source by these steps:

right click the project => build path=> configure build path=> libraries => source attachment => give the path of the source code downloaded.

But, I didn't get any solution for my debug. Again, when clicking on the spinner it opens the debug that android.jar has no source attachment.


This is now really easy!

Go to Window->Android SDK Manager and install "Sources for Android SDK".

Now try to control-click some Android identify, you will get the usual "no source attached" page. Click "Attach Source" and get the option to select an external folder.

Now browse to /home/me/android-sdks/sources/android-16 (or wherever your SDK is installed; this is the default), and hit ok.

It should think for a moment and then display the source! Yeay!


Unless you need older API sources, you are probably better served by Timmmm's answer. If you do need sources older than 14, read on...

In Eclipse simply go to

Help -> Install New Software

then add update site

http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/

and go through the motions to install it.

This will happily provide sources for all installed API versions and works very well for me. Some more documentation is here

http://code.google.com/p/adt-addons/

look for the heading Android Sources


If adding folder android-sdks/sources/android-17 as external source doesn't work (as in my case) you can try to create folder android-sdks/platforms/android-17/sources/android-17 copy sources to it and restart eclipse (I have eclipse Juno Service Release 1). Only this way works for me.

Steps to do this for android-17:

  1. Go to the adroid-sdk install folder, for me it's d:\ws\android-sdks\
  2. Copy android-17 sources folder from android-sdks\sources\android-17\ to the android-sdks\platforms\android-17\sources\ (your have to create folder sources here manually) folder so the final path to the sources must be the: android-sdks\platforms\android-17\sources\android-17\
  3. restart the eclipse, it must automatically attach sources for android-17

UPD: the same solution with symlinks:

Windows Vista+ (thanks @saleemrashid1 for mentioning mklink in comments):

1. cd platforms\android-17
2. mklink /D "sources\android-17" "..\..\..\sources\android-17"

For Unix-base OSes (@Joe comment):

it works fine to create the directory and symlink "sources/android-XX" to "../../../sources/android-XX":

mkdir platforms/android-19/sources && 
ln -s ../../../sources/android-19 platforms/android-19/sources/android-19.