Browsing Android 2.2 (Froyo) Source code in Eclipse
No matter how good an API documentation is, if you have access to the code. The code is the best documentation.
Android is huge in scale becoming automatically poor in documentation. It’s getting better and better everyday but so far I’ve needed to pop the hood for a more thorough look every now and then.
The source code isn’t distributed with the SDK, and my beloved jadclipse just goes bananas when I try to open any of its class files.
You could always browse the source tree online but it isn’t just as effective and me being the possessive freak I am couldn’t let it go. So here is what I did to be able to browse from eclipse, you don’t have to go through with all of this a link to the resultant jar file is at the end of the post:
1-Went to http://android.git.kernel.org/
2-Followed the instructions to install git and repo
3-Started with the base package (Framework classes) – added more as I went along but I only started with the base.git and you’ll probably only need this.
4-Zipped the sources (only the java files) !!
5-Pointed eclipse to the source jar. <If you cannot do this the normal way and eclipse says the source attachment on the library cannot be changed check the instructions below>.
and voila !! you can view the source by control+clicking any class you like.. download the sources jar here.
In case Eclipse won’t let you update the source attachment on the ADT library called Android 2.2:
1-From the window menu select preferences.
2-In the search control on the top of the menu search for user library.
3-Pick the one under Java.
4-Create a user library (call it ‘MyAndroid 2.2? for example).
5-Click ‘Add jar’ and browse for android .jar (found under YourAndroidSdkDir/platforms/android-8).
6-Click javadoc attachment and click edit then browse for there reference directory (found under YourAndroidSdkDir/docs), you will need to write it as a file url though i.e. start with file:/ and if you are under windows use slashes instead of backslashes in the path.
7-Click source attachment and click edit then browse for the source jar you’ve downloaded from this post.
8-Right click the library Android 2.2 from your project layout view and from the build path menu click remove (your project should be all red now =) ).
9-Finally right click your project and from build path select to add user library and your library should be there.
Happy Hunting !







>5-Pointed eclipse to the source jar.
How do you actually do this?
@Alex you just right click the android.jar from your project layout, select properties, from the menu on the left click source attachement and point to the archive in the post. You might need a refresh afterwards (it should work but sometimes when you do this it just doesn’t).
@Alex Ok I can see your problem, due to some errors with the version of eclipse I was using I didn’t use the (Android built in lib) I had to create my own user library and add it to the build path instead.
So here is how you do it, I will add this to the post above later.
1-You go window preferences.
2-In the search control on the top of the menu search for user library.
3-Pick the one under Java.
4-Create a user library (call it ‘MyAndroid 2.2? for example).
5-Click ‘Add jar’ and browse for android .jar (found under /platforms/android-8).
6-Click javadoc attachment and click edit then browse for there reference directory (found under /docs), you will need to write it as a file url though i.e. start with file:/ and if you are under windows use slashes instead of backslashes in the path.
7-Click source attachment and click edit then browse for the jar you’ve downloaded here.
8-Right click the library Android 2.2 from your project layout view and from the build path menu click remove (your project should be all red now =) ).
9-Finally right click your project and from build path select to add user library and your library should be there.
Thanks!! I should have figured this one out my self though
I don’t know whether this was the case when you wrote your post, but GrepCode has an
entry for the source archive now. Check it out:
http://grepcode.com/snapshot/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1
It is also available in the Maven repository:
http://repo1.maven.org/maven2/com/google/android/android/
Check this
http://stuffthathappens.com/blog/2008/11/01/browsing-android-source-in-eclipse/
Hi, I recently created a script that downloads every Android sources and creates a .jar archive for each version.
You can download android sources .jars and/or get the script’s code here :
http://paul-wintzer.fr/?q=node/7
Thanks a lot, Mohammady!
Its working good. I need same for Android 1.5 also, could you provide it also?
tv online…
http://www.tv-online-live.com...
Hi…
http://www.webcamgirls4.com/...