Eclipse中查看源码

本文介绍如何将Android源码集成到Eclipse中进行查看。通过创建一个名为'sources'的文件夹,并将源码放置其中,或者创建Eclipse用户库来实现。文章提供了两种解决方案,并详细说明了每一步的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Examining the Source

When you download the Android source, you get EVERYTHING. This includes the OS, the Dalvik VM, the Eclipse Plugin, the public SDKs, etc.

In the com.android.ide.eclipse.adt.project.internal package, I found
a class named AndroidClassspathContainerInitializer.java. This has
the following code:

IPath android_src = new Path(AdtPlugin.getOsAbsoluteAndroidSources());

OK, fine. So looking inside AdtPlugin.java:


/** Returns the absolute android sources path in the sdk */
public static String getOsAbsoluteAndroidSources() {    
	return getOsSdkFolder() + getOsRelativeAndroidSources();
}
/** Returns the android sources path relative to the sdk folder */
public static String getOsRelativeAndroidSources() {    
	return AndroidConstants.FD_ANDROID_SOURCES;
}
And finally inside AndroidConstants.java:

public static final String FD_ANDROID_SOURCES = "sources";

I win!

Solution #1

Based on the above analysis, you need to create a directory named “sources” inside your Android SDK installation. So right next to your android.jar, create a sources directory.

Now that you have this directory, you can find the appropriate source directories in the Android sources that you pulled from Git. Google’s checkout directions suggest a directory named ‘mydroid’, so I’ll use that here. The public SDK source is found in mydroid/frameworks/base/core/java. Under that folder you’ll find an android directory, which should be copied (or symlinked) over to the sources directory in your SDK installation.

You’ll have to do some hunting around to find all of the source code, it’s kind of sprinkled all over the place in the mydroid directory tree. In the end, you should have something like:

SDK_PATH
  | android.jar
  +--docs/...
  +--samples/...
  +--sources
       +--android
       |      ...accounts, annotation, app, bluetooth, etc...
       +--com/android/etc...
       +--dalvik/...
       +--java/...
       +--javax/...


I grabbed all kinds of directories, and I didn’t take good notes, so I probably missed a few and inadvertently added too many. You probably only really need the public SDK sources, but I think it’s nice to also study implementation classes, as well.


Solution #2

If you’d rather not copy (or link) all of those source directories into your SDK directory, you can also create an Eclipse User Library. At first, I tried creating my own library containing android.jar, but Eclipse complained about that being a duplicate .jar file. So instead, I picked an arbitrary JAR file as my user library, and then proceeded to attach all of the Android source directories to that library.

My user library seemed to do the trick, but I like having that sources directory because I don’t have to remember to add the user library to each new project I create.


在sdk的某个版本下新建个sources目录,然后拷上源码即可

如:E:\android-sdk-windows-2.0.1\platforms\android-1.6\sources

摘自: http://stuffthathappens.com/blog/2008/11/01/browsing-android-source-in-eclipse/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值