Home > android, tools > Installing Android sources into Eclipse for debugging

Installing Android sources into Eclipse for debugging

A couple of weeks ago I installed Android sources into my Eclipse environment. My primary motivation was to get JavaDoc comments in code assist, but those sources were also picked up by the debugger.

The problem with mismatched Android version sources

It’s pretty common when developing for Android to build the application with one version of Android SDK and debug with another (typically earlier) version. My environment is no exception: I build with Android 2.2 SDK, and debug on a Motorola Milestone that runs 2.1update1 (which will never be updated to 2.2, but that’s another story). This means that the sources installed for JavaDoc and code assistance are, strictly speaking, not the right ones for debugging, as you can see in the screenshot below:

performLaunchActivity vs. startActivityNow

The debugger says the application is stopped inside performLaunchActivity, but the source window shows startActivityNow. Let’s fix that.

Getting the right sources (again)

My development phone is a Motorola Milestone running 2.1update1, so I needed to find the right (or close enough) version of the base Android framework in the repository here:


I found what looked like 2.1update1 for my Milestone at the bottom of that page; it was a branch called “eclair-sholes-release2” (“sholes” being the codename for Motorola Droid / Milestone architecture, and assuming that “eclair-sholes-release” was the first 2.1 release).

sholes-release-2 branch

In addition to the list of branches, the page also has a list of tags, which is another place to look for a particular version of Android.

Clicking on “eclair-sholes-release2” took me to this page:


which doesn’t have a download link, so I replaced “a=shortlong” with “a=snapshot” in the URL:


Source code from major release-specific branches can be downloaded like this:


You can get other versions by changing the branch name (froyo) in the link above (to donut, gingerbread, etc.)

Extracting the sources

This is how I extracted the sources on my computer, nothing special:

Extracting the sources

Pointing the debugger at the sources

The debugger has its own setting for source code lookup, which is separate from the “source attachment” to android.jar used before. To set this, switch to the debug perspective, then right-click on your running application, and select “Edit Source Lookup”, then proceed as shown below.

The left screenshot below also shows a deliberate error I made in one of my layouts, by having a ScrollView with more than one child, thus making my application crash.

The right screenshot shows how to select the right folder where Android 2.1u1 sources were extracted.

Bringing up debugger source lookup

Selecting the sources directory

This completes the setup.

The right source code version shown after a crash

This is what I get now instead of the misaligned source code shown near the top of this page. Looks like a pretty significant improvement to me:

Matching sources and variables

Categories: android, tools
  1. August 6, 2012 at 2:21 pm

    nice post…
    thanks for sharing this article…please keep touch this blog…
    this blog is useful like me..

  2. kp
    February 24, 2011 at 4:37 pm

    Kostya – thanks for this, it’s very helpful to me.

    Errata: minor typo

    Source code from major release-specific branches can be downloaded like this:


    this link pulls a 500 server error, but if you change the “h=” parameter to h=refs/heads/froyo, it works great

  1. January 29, 2011 at 11:46 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s