On The Insider: Britney's Bikini-Clad Top 10
BNET Business Network:
BNET
TechRepublic
ZDNet

January 12th, 2009

Browsing Android Source in Eclipse

Posted by Ed Burnette @ 6:19 am

Categories: Eclipse, General, Programming

Tags: Eclipse, Android, Michael Forster, Java Development Tools, Open Source, Development Tools, Software Development, Software/Web Development, Ed Burnette

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:

Ed BurnetteEd Burnette is a professional developer and author of several articles and books about computing including Hello, Android: Introducing Google's Mobile Development Platform, 2nd Edition. For disclosure of Ed's industry affiliations, click here or to view his full profile click here.

Email Ed Burnette

Subscribe to Dev Connection via Email alerts or RSS.

Related Discussions on TechRepublic

Did you know you can take part in these discussions with your ZDNet membership?

  • Talkback
  • Most Recent of 2 Talkback(s)
RE: Browsing Android Source in Eclipse
I'm trying to make this both quick and easy for people, at least until Google gives us something better. See my article and pass it on if it helps (or let me know if it doesn't):

Read the rest)
Posted by: sosiouxme Posted on: 01/19/10 You are currently: a Guest | | Terms of Use
Easy Java code browsing...  zvikico | 01/12/09
RE: Browsing Android Source in Eclipse  sosiouxme | 01/19/10

What do you think?

SponsoredWhite Papers, Webcasts, and Downloads

advertisement

Recent Entries

Archives

Favorite Links

ZDNet Blogs

White Papers, Webcasts, and Downloads