Friday, February 20, 2009

View Android Source Code in Eclipse

Recently I was working with my friend from Hitachi software in Japan about our patent invention VSF during our time at U of M. I was very impressed that he has made a comercial product, anyWarp for BREW,based on that patent. This reminds me about Android and I started working on it since then.

Android is awesome but its SDK doesn't boundle source jar file. I guess Google just wants to place some mental challenges on us because the instruction of getting source code and making it work inside Eclipse is hard to follow. Well, I found some posts on this issues but I have to combined them together to get it work (unfortunately, none of them works for my case individually). I have a Windows XP (sp3) PC and a Redhat Linux machine (RHEL WS4). Here is my procedure to save people's time:
1. Download Android SDK and install it.
2. Install Git on the Linux machine. (current version is:
3. Goto Linux machine to get the Android source code:
$ mkdir Android; cd Android
$ git clone git:// android-api
$ cd android-api; git checkout
4. zip all java files under android-api directory but preserve the directory structure.
$ find . -type f -iname "*.java" -print | xargs zip -
I have uploaded (ver 1.0r2) onto my googlepages site. You can skip previous step 2 to step 4 if you use source I built.
5. copy over the created into the Android SDK folder on Windows. Just put it side-by-side with android.jar
6. Inside Eclipse, let's assume you have already loaded Android sample projects correctly and you have source code already. But the Android Eclipse plugin doesn't allow to modify the Java source attachment of android.jar in the Android Library. See Eric Burke's post for detail. But, I just want to do a little different than his approach because it doesn't work for me when I follow his instruction on creating sources folder.
7. Follow the steps:
a. Select the project on Eclipse and right click mouse and choose Properties.

b. Select the Android Library and hit "Remove" to remove it.
c. Hit "Add External JARs..." and select android.jar from Android SDK installation folder. Now, android.jar is treated as the normal jar file.
d. Now, you can go ahead to attach to android.jar just like any other java source attachments for jar files.
8. I have tested it and it works great. Also, if multiple Android projects exist inside workspace, the step 7 only needs to be done for only one project and others just work immediately without any change.

No comments:

Post a Comment