Friday, October 28, 2011

How to attach sources for SDK classes?

Ability to see SDK sources was one of the requests files in our JIRA for a while. I am glad to announce that is ready now. You have to find these sources somewhere because Android SDK does not ship with them. For example Mike Foster wrote a script long ago. The idea is to clone git repository with Android sources and collect the sources from various locations there. Once you have it extract them into $ANDROID_SDK/platforms/<platform-dir>/sources folder where platform is one of android-X directories. Substitute API level of your project for X.

For those interested in details there is a long discussion in related bug report from Eclipse users.

3 comments:

  1. I'm using NBandroid every day, and it's a joy to follow how it progresses.
    Thanks for your work, Radim!!

    BTW in case someone missed HOW to do this, you can download Android source ZIPs from e.g.:
    http://rgruet.free.fr/public/

    Download for example, android-2.3.3-gingerbread-src.zip.

    And then, to attach the sources, you need to define a library: Tools | Libraries | New Library...
    Call it for example android-2.3.3-gingerbread. Then you add android-sdk-linux_86/platforms/android-10/android.jar in Classpath tab and the android-2.3.3-gingerbread-src.zip in the Sources tab.

    Note that you will never *use* this library.
    Just having it *defined* will bind platforms/android-10/android.jar to android-2.3.3-gingerbread-src.zip.

    Note also that the other Android versions needs to get the same binding if you want to browse sources with them.

    I usually just switch to android-10/2.3.3/gingerbread when I want to browse the sources.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I notice that the SDK Manager includes an option for the sources, only for some API versions. However it puts the sources in $ANDROID_SDK/sources/ instead of $ANDROID_SDK/platforms/sources. It would be sweet to add support for this in the plugin.

    ReplyDelete