views:

888

answers:

2

When you are developing an Android application with the Eclipse plugin and debugger, and get a stack trace, you will not see any of the SDK source code. What steps do you need to make to fix this? Assume beginner Java programmer.

To clarify, I want Eclipse to automatically show me the correct source files and lines when I jump into a stack frame. I assume I would need to find the correct SDK sources, put them on my local system and then tell Eclipse how to find and use them. The question is, how exactly do I do these steps.

A: 

If you look at your launch configuration in Eclipse (Debug->Run as...), you will see a tab called "sources"

If you choose "add" and then supply an archive or file system directory with the relevant sources, the debugger is supposed to allow you to trace into them.

You can get the sources of the SDK from the Android site, just make sure your Jar and your sources version are the same.

Uri
There is no sources tab for Android configurations. The available tabs are: Android, Target and Common. None of them have any place to set sources. (Regular Java configurations do seem to have sources tab.)
Heikki Toivonen
+4  A: 

Thanks to lukehutch on #android IRC channel I got pointed to a blog post that describes how to fix the problem.

The reason why this is even a problem is because Google did not include the sources with the SDK. There is a bug to get this fixed.

The workaround, as described in more detail in the blog post, is to get the sources with git (I specified release-1.0 branch for repo command which I hope corresponds with SDK 1.0-r2), collect all the java source files and put them in the correct directory structure under sources/ directory (which goes right next to your android.jar from the SDK), and refresh the jar in Eclipse at which point you can browse the SDK class sources.

Finally, run your application in the debugger until you get a stack trace from an SDK class, and you will see a button to configure your sources: add the sources directory you created.

The blog link above has a small Python script that can collect all the java files and create the correct directory structure out of them.

Heikki Toivonen