X
Tech

Browsing Android Source in Eclipse

When developing Android programs in Eclipse you can use features like hover-help (hover your mouse over a class name and Eclipse will display the JavaDoc for that class) and code completion (press Ctrl+Space and Eclipse will suggest methods, fields, and classes appropriate for the context). However one thing is missing: the actual Android source code.
Written by Ed Burnette, Contributor

When developing Android programs in Eclipse you can use features like hover-help (hover your mouse over a class name and Eclipse will display the JavaDoc for that class) and code completion (press Ctrl+Space and Eclipse will suggest methods, fields, and classes appropriate for the context). However one thing is missing: the actual Android source code. You can fix that shortcoming, but it's not easy or quick.

If you navigate to an Android class (for example, Ctrl+Click on a class name or break on an exception in the debugger) you'll get a window that says "Source not found". The Android source is not currently included in the SDK. I think it should be, and if you agree then please add your star to Issue 979 in the Android issue tracker. In the meantime, you can download the source manually from source.android.com and then move all the Java sources into a "sources" subdirectory of the Android SDK.

It sounds easier than it is. First you'll need about 2GB of spare disk space, and you'll need to install the "git" program (and cygwin if you're running Windows), use git to download the source, and then rearrange the source into a standard Java source directory structure where the path of the source file matches its package name. Michael Forster has written a python program to do that last part for you. Remember to do a File > Refresh after you have everything set up.

Note that the class files supplied with the SDK are stubs, not the real classes used on the device. Google did it this way to prevent you from accidentally using non-public APIs. Usually this won't matter, but it does explain why a decompiler plug-in won't help you. You'd just decompile a bunch of stub code. By pointing Eclipse at the real source, your source code and the code on the target device (or emulator) should be a close match. It won't be exactly the same because changes might have been made to the source tree after the code was compiled, but it should be close enough.

For instructions and more details, see the following articles:

Editorial standards