如何在 Eclipse 中附加 Android 支持库源代码?

发布于 2024-12-21 19:21:10 字数 187 浏览 5 评论 0原文

将源代码附加到外部库真是太棒了。在哪里可以找到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

痴骨ら 2024-12-28 19:21:10

我只是想添加另一种附加支持库源的方法。 它需要版本 20 或更高版本的 ADT。据说此方法适用于容器禁用设置源/javadoc 位置的所有 JAR。您需要执行以下操作:

  1. android-support-v4.jar 库位于项目的 libs 目录中。在同一目录中创建一个常规 Java 属性文件,其名称与相关 JAR 完全相同,但附加了 .properties 扩展名。因此,对于我们的支持库来说,它将是:
    android-support-v4.jar.properties

  2. 打开创建的属性文件,并将名为 src 的属性值设置为可以找到该库源的位置。您的文件应该包含一行,例如:

    src=c:/apps/adt-bundle-windows-64bit/sdk/extras/android/support/v4/src
    
  3. 保存文件。

  4. 关闭并重新打开您的 Android 项目。

  5. 尝试浏览到支持类别之一。源附件现在应该可以工作了。

在我的例子中效果很好。

需要注意的一件事是:如果 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:

  1. The android-support-v4.jar library lies in the libs 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.

  2. 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:

    src=c:/apps/adt-bundle-windows-64bit/sdk/extras/android/support/v4/src
    
  3. Save the file.

  4. Close and re-open your android project.

  5. 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 - if src=support/src, ADT will assume that the class sources are located in libs/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 in eclipse/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.

沧笙踏歌 2024-12-28 19:21:10

这里是在 Eclipse Juno 中附加支持库源的解决方案

我想您的项目已经在“构建路径”中的“Android 依赖项”下有 android-support-v4.jar ,但是您无法将源目录附加到它。 (“源附件”表示“不可修改”)。解决方案:

  • 转到“配置构建路径”
  • 添加外部 JAR > YourProject/libs/android-support-v4.jar
    (我知道您的项目已经引用了它,但不用担心,只需再次添加即可)。
  • 展开 jar 并将源附加到外部 Jar: android-sdk/extras/android/support/v4/src
  • 切换到“Order and Export”选项卡,将外部 jar 拉到“Android Dependencys”上方“

享受浏览支持库及其源代码的乐趣!

如果您有一个附加到 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:

  • Goto "Configure Build Path"
  • Add External JARs > YourProject/libs/android-support-v4.jar
    (I know your project had already referenced to it but don't worry, just add it again).
  • Expand jar and attach Source to the External Jar: android-sdk/extras/android/support/v4/src
  • Switch to the "Order and Export" tab, pull up the external jar above the "Android Dependencies"

Enjoy navigating the support library with source!

if you have an "Android Test Project" attached to YourProject, so YourProjectTest 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.

柒七 2024-12-28 19:21:10

从 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.

桃酥萝莉 2024-12-28 19:21:10

参考已接受的答案,也可以直接从目录附加源代码,而无需构建 .jar 文件。从 Java 构建路径/库选项卡中,展开 android-support-v4.jar,突出显示“源附件”,单击“编辑...”、“外部文件夹...”,然后指向 (android-sdk)\extras\安卓\支持\v4。

这是使用 eclipse indigo 进行测试的。

来自评论:

如果您的支持库位于项目的“Android Dependencies”文件夹中,则似乎会出现无法将源添加到支持库的问题。解决方法是从同一个“Java 构建路径/库”选项卡中单击“添加外部 JAR...”,然后在 (android-sdk)\extras\android\support\v4 路径中找到 .jar 文件。然后它将出现在您的项目设置中的新“参考库”文件夹下。

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:

The problem of being unable to add source to the support library seems to occur if your support library is located in the "Android Dependencies" folder of your project. The workaround is from the same "Java build path / libraries" tab click "Add External JARs..." and find the .jar file in your (android-sdk)\extras\android\support\v4 path. It will then appear in your project setup under a new "Referenced Libraries" folder.

金橙橙 2024-12-28 19:21:10

对于那些喜欢标准的人来说,拥有源代码的jar文件,这使得源代码控制和共享项目更加方便。

例如:

../android-support-v4.jar
../android-support-v4-src.jar

创建源 jar 文件并将其附加起来很简单:

  1. cd 到 path_to_android_sdk/extras/android/compatibility/v4/
  2. 使用您最喜欢的 zip 程序(例如 7-zip)创建一个zip 文件并将其命名为 android-support-v4-src.jar。 jar 中的第一个文件夹应该是 /scr。
  3. 将文件复制到您的项目中,在本示例中,它与代码 jar 位于同一文件夹中。
  4. 在 Eclipse 中,将源 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:

  1. cd to path_to_android_sdk/extras/android/compatibility/v4/
  2. Use your favorite zip program such as 7-zip to create a zip file and name it android-support-v4-src.jar. The first folder in the jar should be /scr.
  3. Copy the file to your project, in this example it is in the same folder as the code jar.
  4. In Eclipse attach the source jar in project properties.
时光无声 2024-12-28 19:21:10

我只是删除自动生成的库,然后手动将其添加为参考库。

首先打开一个类,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.

你不是我要的菜∠ 2024-12-28 19:21:10

从构建路径附加 src 和 doc 的过程适用于某些人,但不适用于某些人(比如我)。需要记住的一些关键事项

  1. 确保您位于Package Explorer,而不是Project Navigator

  2. 如果您已将 android-support-v4.jar 放入项目下的 libs 文件夹中。太棒了。

  3. 右键单击 jar,构建路径..添加到路径。 (如果“添加到路径”没有显示,那么它已经添加了。您将看到配置路径..)

  4. 作为第 3 步的结果,一个名为参考库的新文件夹将出现在包资源管理器中树。打开该树,找到 android-support-v4.jar 。在参考库属性中右键单击此 jar。然后在那里设置 Java Source Attachment 和 Javadoc Location。

  5. 你已经完成了。

我的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

  1. Make sure you are in Package Explorer, not Project Navigator.

  2. If you have put your android-support-v4.jar in libs folder under your project. great.

  3. 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..)

  4. 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.

  5. 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

飘逸的'云 2024-12-28 19:21:10

我为我找到了这个:

对于主库: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)

他夏了夏天 2024-12-28 19:21:10

更新 SDK 并下载其中的文档后:

  • 将支持库项目导入到包资源管理器。
  • 在库中创建一个文件夹并将其命名为 ext-jars
  • android-support-v4.jar 移动到 ext-jars 文件夹。

    “在此处输入图像描述”"

  • 右键单击​​该项目,然后单击“属性”。
  • 单击左侧菜单中的 Java Build Path,然后选择 Libraries 选项卡。
  • 单击Add JARs...,然后展开项目并选择已移至文件夹ext-jars 的 jar 文件。

输入图片此处描述

  • 展开添加的 jar 并选择源附件,然后单击编辑
  • 选择外部位置,然后单击外部文件夹...
  • 选择位于以下位置的 Support v4 的源文件夹
    [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:

  • Import support library project to package explorer.
  • Create a folder in the library and name it something like ext-jars.
  • Move android-support-v4.jar to ext-jars folder.

    enter image description here

  • Right click on the project and click on Properties.
  • Click on Java Build Path in the left menu then select Libraries tab.
  • Click on Add JARs... then expand the project and select the jar file you already moved to folder ext-jars.

enter image description here

  • Expand the added jar and select Source attachment then click on Edit.
  • Select External location then click on External Folder...
  • Choose the source folder for the Support v4 which is located in
    [sdk-path]/extras/android/support/v4/src

enter image description here

  • Select Javadoc location click on Edit then select Javadoc URL then click on Browse... and choose the javadoc location for support v4 which is located in [sdk-path]/docs/reference/

enter image description here
- Select Order and Export tab and check the android-support-v4.jar you just added.

I suggest you also clean the project and reopen the Eclipse.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文