16 April 2011

Android Sources in Eclipse

I've blogged about getting Eclipse to show Android sources before, but these techniques no longer work. So I'll toss a working how-to out there again.


I'm still baffled that Google hasn't ensured this working from day #1 with this eclipse plugin. But enough crying :)


I should also mention there is an eclipse plugin made for this. I've never tried it. I don't like bloating eclipse with tons of plugins, unless I really have to. And this boils down to 8 pretty easy steps, so an eclipse plugin isn't something Id'e consider. (But I may change my mind later)

Download the sources from github, and attach them:
  • Click the Snapshot link which just appeared by the Tree -link

You'll start downloading a file which is about 130mb. This is the android source file. It's filename starts with base, for me it's called base-08d9d9a.tar.gz
  • move the base -file to the SDK platform directory, for me that's /opt/android-sdk-linux_x86/platforms/android-8
  • unpack it (tar xvfz base-08d9d9a.tar.gz).
  • head into eclipse, and press F3 over some android source you're missing, like Activity. And get this pesky window, which we all hate:

  • Click Attach Source, choose External Folder, and choose the core/java in the base folder. For me that's /opt/android-sdk-linux_x86/platforms/android-8/base-08d9d9a/core/java
There you go. Please post a comment and tell me how this turns out for you :)


.finn


(*1) There are loads of versions there, and it's a bit confusing. I've concluded the stuff we're looking for should end with SDK. However I'm not 100% certain about what version to download to match the Android version we see in the Android SDK download tool - this is just me guessing.

6 comments:

  1. Nice information -- also, instead of getting an entire snapshot, you can also just get the folder core/java. For example, for Android 2.2 Release 2: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=tree;f=core/java;h=5dd97005eca0ab0323bfe5b08d09e07d3ac31347;hb=ec1a8f7aa7e71e292ef813b1e886a9e26e3635af.

    And then after you download the tar file, you just need to rename it to "sources", and Eclipse will pick it up.

    ReplyDelete
  2. thanks a lot man, it works.

    ReplyDelete
  3. The link originally posted here doesn't go to the android source code anymore.
    Try here now: https://github.com/android/platform_frameworks_base

    ReplyDelete
    Replies
    1. thanks for the updated link!

      Delete
  4. Thanks man, it is a nice approach, it worked at my end.

    Regards.

    ReplyDelete