如何在 Eclipse 中附加 Android 支持库源代码?
将源代码附加到外部库真是太棒了。在哪里可以找到 v4 支持包 的源代码?最好是一个 zip 文件,可以轻松附加到 Eclipse 中的 android-support-v4.jar
中。
Having the source code attached to external libraries is awesome. Where do I find the source code for the v4 support package? Preferably, it would be a zip file which could be easily attached to the android-support-v4.jar
in Eclipse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
我只是想添加另一种附加支持库源的方法。 它需要版本 20 或更高版本的 ADT。据说此方法适用于容器禁用设置源/javadoc 位置的所有 JAR。您需要执行以下操作:
android-support-v4.jar
库位于项目的libs
目录中。在同一目录中创建一个常规 Java 属性文件,其名称与相关 JAR 完全相同,但附加了.properties
扩展名。因此,对于我们的支持库来说,它将是:android-support-v4.jar.properties
。打开创建的属性文件,并将名为
src
的属性值设置为可以找到该库源的位置。您的文件应该包含一行,例如:保存文件。
关闭并重新打开您的 Android 项目。
尝试浏览到支持类别之一。源附件现在应该可以工作了。
在我的例子中效果很好。
需要注意的一件事是:如果 src 不是绝对路径,则会从 JAR 文件的父目录开始解析。以支持库为例 - 如果
src=support/src
,ADT将假定类源位于libs/support/src
中。您可以在此处找到该功能的作者撰写的简短说明。
如果有人对这个
.properties
文件的处理方式感兴趣,我建议阅读补丁集 #4,尤其是。eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java
中的更改:)编辑
另请参阅 WindRider 关于在具有多个引用库的项目中正确添加源的精彩评论。
I just want to add yet another method of attaching sources for the support library. It requires ADT in version 20 or later. Supposedly this method works for all JARs for which setting source/javadoc location is disabled by the container. Here's what you need to do:
The
android-support-v4.jar
library lies in thelibs
directory of your project. In that same directory create a regular Java properties file named exactly like the JAR in question, but with appended.properties
extension. So, for our support library it'll be:android-support-v4.jar.properties
.Open created properties file and set value of property named
src
to the location where sources for that library can be found. Your file should have one line like:Save the file.
Close and re-open your android project.
Try browsing to one of the support classes. The source attachment should work now.
Worked perfectly in my case.
One thing to note: if
src
is not an absolute path, it will be resolved starting in the parent directory of the JAR file. Taking support library as an example - ifsrc=support/src
, ADT will assume that the class sources are located inlibs/support/src
.Short description of this feature written by its author can be found here.
If anyone is interested in how exactly this
.properties
file is processed, I recommend reading patch set #4, esp. changes ineclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ internal/project/LibraryClasspathContainerInitializer.java
:)Edit
Please also see a fine comment by WindRider about adding sources properly in a project with multiple referenced libraries.
这里是在 Eclipse Juno 中附加支持库源的解决方案
我想您的项目已经在“构建路径”中的“Android 依赖项”下有
android-support-v4.jar
,但是您无法将源目录附加到它。 (“源附件”表示“不可修改”)。解决方案:YourProject/libs/android-support-v4.jar
(我知道您的项目已经引用了它,但不用担心,只需再次添加即可)。
android-sdk/extras/android/support/v4/src
享受浏览支持库及其源代码的乐趣!
如果您有一个附加到
YourProject
的“Android 测试项目”,那么YourProjectTest
可能不再编译。在这种情况下,您必须返回“订购和导出”并下拉“Android 依赖项”下方的外部 jar,以使事情恢复正常。Here the solution to attache the source of the support library in Eclipse Juno
I suppose that your project already has
android-support-v4.jar
in your "Build Path", under "Android Dependencies", but you cannot attach the sources directory to it. (the "Source attachment" said "Non modifiable"). Solution:YourProject/libs/android-support-v4.jar
(I know your project had already referenced to it but don't worry, just add it again).
android-sdk/extras/android/support/v4/src
Enjoy navigating the support library with source!
if you have an "Android Test Project" attached to
YourProject
, soYourProjectTest
might not compiled anymore. In this case, you have to return to "Order and Export" and pull down the external jar below the "Android Dependencies" to get things back to normal.从 Android SDK Manager 下载支持包后,您可以在文件夹/extras/android/support/v4/src 中找到支持包的源代码。
After downloading the support package from the Android SDK Manager, you can find the source code of support package in folder <android-sdks>/extras/android/support/v4/src.
参考已接受的答案,也可以直接从目录附加源代码,而无需构建 .jar 文件。从 Java 构建路径/库选项卡中,展开 android-support-v4.jar,突出显示“源附件”,单击“编辑...”、“外部文件夹...”,然后指向 (android-sdk)\extras\安卓\支持\v4。
这是使用 eclipse indigo 进行测试的。
来自评论:
Referencing the accepted answer, it is also possible to attach the source straight from the directory without building a .jar file. From the Java build path / libraries tab, expand android-support-v4.jar, highlight "Source attachment", click "Edit...", "External Folder..." then point to (android-sdk)\extras\android\support\v4.
This was tested using eclipse indigo.
From the comments:
对于那些喜欢标准的人来说,拥有源代码的jar文件,这使得源代码控制和共享项目更加方便。
例如:
../android-support-v4.jar
../android-support-v4-src.jar
创建源 jar 文件并将其附加起来很简单:
For those who like the standard to have the jar file of the source code, which makes it more convenient for source control and sharing the project.
For example:
../android-support-v4.jar
../android-support-v4-src.jar
It is simple to create the source jar file and attach it:
我只是删除自动生成的库,然后手动将其添加为参考库。
首先打开一个类,IDE会要求你更改附加源。
I just remove the auto generated one , then manual add it as a Referencde Libraries.
First open a class, the IDE will ask you to Change Attached Source.
从构建路径附加 src 和 doc 的过程适用于某些人,但不适用于某些人(比如我)。需要记住的一些关键事项
确保您位于Package Explorer,而不是Project Navigator。
如果您已将 android-support-v4.jar 放入项目下的 libs 文件夹中。太棒了。
右键单击 jar,构建路径..添加到路径。 (如果“添加到路径”没有显示,那么它已经添加了。您将看到配置路径..)
作为第 3 步的结果,一个名为参考库的新文件夹将出现在包资源管理器中树。打开该树,找到 android-support-v4.jar 。在参考库属性中右键单击此 jar。然后在那里设置 Java Source Attachment 和 Javadoc Location。
你已经完成了。
我的Java源附件的路径。(其外部位置)
C:/Users/thupten/adt-bundle-windows-x86_64-20130514/sdk/extras/android/support/v4/src
我使用android网站文档作为java文档位置
http://developer.android.com/reference/android/support/v4/app/package-summary.html
The process of attaching the src and doc from build path works for some and it doesn't for some (like me). some key things to keep in mind
Make sure you are in Package Explorer, not Project Navigator.
If you have put your android-support-v4.jar in libs folder under your project. great.
Right click the jar, Build path.. Add to Path. (if Add to Path does not show up then its already added. you will see configure path..)
As the result of step 3, a new folder called Referenced Libraries will appear in package explorer tree. Open that tree, find the android-support-v4.jar there. Right click on this jar in the Referenced Libraries, properties. Then set the Java Source Attachment and Javadoc Location there.
You are done.
The path for my Java Source Attachment.(its external location)
C:/Users/thupten/adt-bundle-windows-x86_64-20130514/sdk/extras/android/support/v4/src
I used the android website doc for java doc location
http://developer.android.com/reference/android/support/v4/app/package-summary.html
我为我找到了这个:
对于主库:android.jar:
src: sdk/sources/android-19
doc: sdk/docs/reference/
对于支持库:android-support-v4.jar:(在此之前我们应该像外部 jar 一样添加 android-support-v4.jar (项目属性 -> Java 构建路径 -> 库,然后在“Order and Export”选项卡中在 Android Private Libraries 之前拉出此库)):
src: sdk/extras/android/support/v4/src/java
文档: http://developer.android.com/reference /android/support/v4/app/package-summary.html (不确定)
I found this for me:
For main lib: android.jar:
src: sdk/sources/android-19
doc: sdk/docs/reference/
For support lib: android-support-v4.jar: (before this we should add android-support-v4.jar like external jar (Project Properties -> Java Build Path -> Libraries, then in Tab ‘Order and Export’ pull up this library before Android Private Libraries)):
src: sdk/extras/android/support/v4/src/java
doc: http://developer.android.com/reference/android/support/v4/app/package-summary.html (not sure)
更新 SDK 并下载其中的文档后:
ext-jars
。将
android-support-v4.jar
移动到ext-jars
文件夹。Add JARs...
,然后展开项目并选择已移至文件夹ext-jars
的 jar 文件。源附件
,然后单击编辑
。外部位置
,然后单击外部文件夹...
[sdk-path]/extras/android/support/v4/src
Javadoc 位置
单击编辑
然后选择Javadoc URL
然后单击浏览...
并选择支持 v4 的 javadoc 位置,该位置位于[sdk-path]/docs/reference/
- 选择
Order and Export
选项卡并检查您刚刚添加的android-support-v4.jar
。我建议您还清理项目并重新打开 Eclipse。
After you have updated the SDK and downloaded Documentations in it:
ext-jars
.Move
android-support-v4.jar
toext-jars
folder.Add JARs...
then expand the project and select the jar file you already moved to folderext-jars
.Source attachment
then click onEdit
.External location
then click onExternal Folder...
[sdk-path]/extras/android/support/v4/src
Javadoc location
click onEdit
then selectJavadoc URL
then click onBrowse...
and choose the javadoc location for support v4 which is located in[sdk-path]/docs/reference/
- Select
Order and Export
tab and check theandroid-support-v4.jar
you just added.I suggest you also clean the project and reopen the Eclipse.