Google's Android SDK includes Android.jar, a jar file that contains the Android public API class file. They also provide an eclipse plugin, which makes development on Android quite simple. However, you cannot find Androidsrc.jar this jar file, so when you want to see the Android SDK source code in Eclipse, you will encounter the situation:
Open source to save us!
Earlier this month, Google opened the full source of Android, which, by the way, was quite large! Anyway, in order to browse through the source code in eclipse, you need to visit http://source.android.com/and follow their instructions to drag everything down with git. Definitely worth a night to do this, because having the full source code makes it easier to understand the SDK's working mechanism.
Attach the source code to eclipse ... Brother, not as fast as you think.
Now that you have the source code, you can tell eclipse where it is located. I have tried to right-click on the Android.jar and select "Properties", but welcome to me is the following:
Hmm ... "The current Classpath entry point belongs to the Android library, which does not allow the user to modify the source attachment at its entry point. "It really got me into a loop, because I usually use idea, so I'm really stumped." So I went deep into the source code and wanted to find a solution.
Test source
When you download the Android source code, you get everything, including operating system, Dalvik virtual machine, Eclipse plugin, public SDK, etc.
In the com.android.ide.eclipse.adt.project.internal package, I found a class called Androidclassspathcontainerinitializer.java. It has the following code:
IPath android_src = new Path (adtplugin.getosabsoluteandroidsources ());
Yes, that's good. Then, go into the Adtplugin.java and look at:
/** Returns The absolute Android sources path in the SDK */public static String getosabsoluteandroidsources () {retur n Getossdkfolder () + getosrelativeandroidsources (); }
/** Returns The Android sources path relative to the SDK folder */public static String getosrelativeandroidsources () { return androidconstants.fd_android_sources; }
Finally, go androidconstants.java and look at:
public static final String fd_android_sources = "SOURCES";
I've done it!
Programme I
Based on the above analysis, you need to create a new directory named "Sources" in your Android SDK installation directory.
Now that you have this directory, you can find the right source directory in the Android source code you downloaded from git. Google's testing guidelines recommend that this directory be named "Mydroid", so I'll use that name here as well. The Public SDK source code can be found here: Mydroid/frameworks/base/core/java. Under that folder, you can find an Android directory that should be copied to the source directory in your Android SDK installation directory.
You will have to do some searching around to find all the source code, it is scattered in the mydroid directory tree everywhere. Finally, you should be able to get such a directory structure:
Sdk_path
| Android.jar
+--docs/...
+--samples/...
+--sources
+--android
| ... accounts, annotation, app, Bluetooth, etc ...
+--com/android/etc ...
+--dalvik/...
+--java/...
+--javax/...
I crawled all the directories, but I didn't make a good record, so I probably added too much without notice. You may just need the public SDK source code, but I think it's great to learn about class implementations.
Now when I browse in the Android SDK class, I see the source code:
Programme II
If you do not want to copy (or link) all the required source directories into your SDK directory, you can also create an Eclipse user library. First, I tried to create my own user library with Android.jar, but Eclipse complained that it would be a duplicate jar file. So, I picked any jar file as my user library and started attaching all the Android source directories to that library file.
My user base seems to work, but I prefer to copy the source directory so that you don't have to add the user library every time you create a new project.
Original: http://www.linuxidc.com/Linux/2011-09/43200.htm