73
votes

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.

7
Change your accepted answer ! And choose WiselyMr_and_Mrs_D

7 Answers

90
votes

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!

85
votes

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

14
votes

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. 
13
votes

To attach source code for android.jar, you may follow the tutorial at the link below: http://android.opensourceror.org/2010/01/18/android-source/ Make sure to choose the correct platform version.

If you meet difficutly with spinner, try to get the sample code and see how it works: http://developer.android.com/resources/samples/get.html

Good luck. :)

Update

This answer is quite out of date, please consider other answers.

1
votes

What worked for me follows the answer found in Murach's Android Programming. I got stuck trying to debug and tried to work it out for about 3 hours before turning to the next page (literally) where it said "Sometimes Eclipse will display a source not found message because...." (-headdesk-)

My solution was to turn on Step Filtering and add the packages that I wanted to skip when debugging. Evidently, Eclipse sometimes steps through all the source code libraries, when all you want is for it to step through your code. You can bypass this by adding the packages you want to skip to the filter. According to Murach, you kinda just do it by trial and error, starting with selecting all packages and adding them. As you continue with debugging you might find you need to add more packages to the filter.

Specific steps: 1. Turn on step filtering; click the button in the toolbar on the top that looks like this: http://i57.tinypic.com/x3iccp.png 2. Go to Window-->Preferences, then in the Preferences dialog, select Java-->Debug-->Step Filtering 3. Select all packages. 4. To add additional filters, click "Add Filter", type the name of the package with a .* at the end, and click OK. Murach recommends adding these common packages to begin: --android.* --com.android.* --com.google.* --dalvik.* --libcore.* --org.apache.* So to add one of these packages, click "Add Filter", type "android.*", and click OK. I ended up having all of the following packages on my Step Filter Preferences.

android., android.app., com.android., com.google., com.ibm., com.sun., dalvik., java., javax., jrockit., libcore., org.apache., org.omg., sun., sunw.*, ((and this last one is a class, not a package)) java.lang.ClassLoader

I had "Use Step Filters" checked at the top of the dialog box, and "Step through filters" checked at the bottom. Click "Apply", then "OK" to close the dialog. It should work.

Good luck!

0
votes

I added appengine sdk and some other sources, and that destroyed my ADT :-(

I saw that for android-16 and android-17, the platform libraries downloaded by SDK Manager started going to ./sdk/sources whereas prior to my adding appenginge sdk, SDK Manager sent platforms to ./sdk/platforms.

It looks like the change is as a result of the appengine sdk, but for ADT, platform APIs should def be going to ./sdk/platforms

The path ./sdk/sources seems like a more generic java location and is probably the 'correct' path. Thus Android, as usual, is the problem. I was pretty sure from this point forward, I would need both ./sdk/sources and ./sdk/platforms, depending on what I was compiling.

So, I moved everything from ./sdk/sources to ./sdk/platform, deleted ./sdk/sources and then created a link 'cd sdk && ln -s platform sources'

Everything works now ;-)

0
votes

For me the only solution which worked was the answer of fsbmain. Kudos to him. I can't comment on his solution because of my low reputation counter. But I want to share my knowledge ;)

I'm working on windows and don't wanted to copy the whole source tree to another location. And copy again on updates etc. So I used the possibility to insert a symbolic link which works since Windows Vista like a charm (or like Linux). For Linux you have to look at the Joe's comment under fsbmain's answer.

Assuming you have the platform in D:\sdk\platforms\android-19. Now you have to make a subdirectory sources and after that create a relative link to the real sources folder.

D:\sdk\platforms\android-19>mkdir sources
D:\sdk\platforms\android-19>cd sources
D:\sdk\platforms\android-19\sources>mklink /D android-19 ..\..\..\sources\android-19

Now restart Eclipse ... Done!