如何生成 Android 类的链接? javadoc中的参考?
当我在 Eclipse 中为 Android 项目生成 javadoc 时,有很多警告,例如
cannot find symbol
symbol : class TextView
,
warning - Tag @see: reference not found: android.app.Dialog
我也在
-link http://developer.android.com/reference/
-link http://java.sun.com/j2se/1.4.2/docs/api/
Configure 中的
(eclipse->项目->生成 Javadoc 的第三个对话框)。Extra javadoc options (带空格的路径名必须用引号引起来)
选项卡中 尝试过Javadoc 参数
但只有 -link http://java.sun.com/j2se/1.4.2/docs/api/
适用于 String 类 生成链接 http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true
。但对于 android.app.Dialog
,不会生成链接。
编辑
我还尝试在选择应生成链接的引用档案和项目
中选择android.jar
为标准 doclet 配置 Javadoc 参数
中的选项卡(eclipse->project->Generate Javadoc 的第二个对话框), 但这会在本地 android-sdk 目录中创建指向文档的本地链接,而不是像 Java API 那样创建在线 Android 参考。
When I generate javadoc for my Android project in Eclipse, there are lots of warnings like
cannot find symbol
symbol : class TextView
and
warning - Tag @see: reference not found: android.app.Dialog
I also tried
-link http://developer.android.com/reference/
-link http://java.sun.com/j2se/1.4.2/docs/api/
in Extra javadoc options (path names with white spaces must be enclosed in quotes)
tab in Configure Javadoc Arguments
(3rd dialog of eclipse->project->Generate Javadoc).
But only -link http://java.sun.com/j2se/1.4.2/docs/api/
is working i.e for String class
link http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true
is generated. but for android.app.Dialog
, no link is generated.
Edit
I also tried selecting android.jar
in Select referenced archives and projects to which links should be generated
tab in Configure Javadoc arguments for standard doclet
(2nd dialog of eclipse->project->Generate Javadoc),
but this creates local links to docs in local android-sdk directory, NOT the online Android references like it does for Java APIs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
Javadoc 依赖于一个名为
package-list
的文件来确定给定目录下记录了哪些 Java 包。由于某种原因,http://d.android.com 缺少这样的文件/reference/,因此“天真的”方法不起作用 - 您会收到一条警告,指出无法检索包列表,并且不会生成文档中的链接。 (注意:第二个 Eclipse 对话框中的复选框只是为您组装
-link
参数,因此实际上没有任何区别)但是,Javadoc 提供了
-linkoffline
参数能够精确地针对这种情况进行调整:您想要链接到其他一些在线 Javadoc 文档,但在生成您自己的文档时无法访问它。它的工作原理如下:-link
仅采用一个参数(您想要链接到的 JavaDoc 文档的 URL),而-linkoffline
则采用第二个参数。那是package-list
文件的位置!因此,要链接到在线 Android 参考文档,您不应在第二个 Eclipse 对话框中选择任何复选框,而应
在第三个对话框中添加“额外 Javadoc 选项”。这样,您就可以使用本地安装的 Android 文档的
package-list
,但生成的 Javadoc 中的链接仍将指向在线版本。希望有帮助!
Javadoc relies on a file called
package-list
to determine what Java packages are documented below a given directory. For some reason, such a file is missing for http://d.android.com/reference/, therefore the "naive" approach withdoesn't work – you get a warning that the package-list could not be retrieved and no links are generated into your docs. (Note: The checkboxes in that 2nd eclipse dialog just assemble
-link
parameters for you, so that doesn't really make any difference)However, Javadoc offers the
-linkoffline
parameter to be able to adjust for precisely this situation: You want to link to some other Javadoc documentation online, but you cannot access it at the time of generating your own docs. Here's how it works: While-link
takes only one parameter (the URL of the JavaDoc docs you want to link to),-linkoffline
takes a second one. That one is the location of thepackage-list
file!So, to link to the online Android reference documentation, you should not select any checkboxes in the 2nd eclipse dialog, but instead add
in the Extra Javadoc options in the 3rd dialog. That way you use the
package-list
of your locally installed Android docs, but the links in your generated Javadoc will still point to the online version anyway.Hope it helps!
截至目前(2020 年 8 月),Google 已在其 Android 开发者文档中发布了
package-list
。因此,只需链接到 https://developer.android.com/reference/ 或 https://d.android.com/reference/ 可以工作(刚刚尝试成功)。小故障:如果您打开生成的 Javadoc 并尝试跟踪 Android 类(或标准 Java 类之一,它也将链接到 Android 文档)的链接,并且您处于框架模式,则您的浏览器可能会拒绝跟踪该链接,因为 Android 站点不允许嵌入到其他页面中。然后,Firefox 为您提供了在新选项卡中打开目标文档的选择。
By now (August 2020), Google has published a
package-list
on its Android developer documentation. Hence, simply linking to https://developer.android.com/reference/ or https://d.android.com/reference/ will work (just tried this with success).Minor glitch: if you open the generated Javadoc and try to follow a link to an Android class (or one of the standard Java classes, which will also link to the Android documentation) and you are in frame mode, your browser might refuse to follow the link, as the Android site does not allow embedding in another page. Firefox then gives you the alternative of opening the target document in a new tab.
经过一番尝试和错误(以及从多个网络搜索中收集到的大量建议),我能够使用特定的 ANT 脚本来实现此功能,该脚本可以通过“Run As -> Ant Build”在 Eclipse 中运行。
我将此文件“javadoc.xml”与 AndroidManifest.xml 文件并行保存在项目目录中。
这是文件的内容:
After a bit of trial and error (And plenty of suggestions gleaned from multiple web searches), I was able to get this working with a specific ANT script, which can be run in Eclipse by "Run As -> Ant Build".
I saved this file, "javadoc.xml", in the directory of my project, in parallel with the AndroidManifest.xml file.
Here is the content of the file:
尽管我遵循此处的最佳答案,但我发现只有导出 ant 构建文件(javadoc.xml)并手动将 android.jar 文件添加到类路径中才能使其正常工作。我的 javadoc.xml 如下所示:
然后我可以使用 ant -f javadoc.xml 生成文档。我无法找到从 Eclipse GUI 正确执行此操作的方法,因为即使选择正确的引用存档也不会导致 Eclipse 将 android.jar 添加到类路径中。
Although I followed to top answer here, I found I could only get it to work if I exported an ant build file (javadoc.xml), and manually added the android.jar file to the classpath. My javadoc.xml looks like:
I could then generate the document using
ant -f javadoc.xml
. I couldn't figure out a way to do it properly from the Eclipse GUI, as even selecting the correct referenced archive did not cause Eclipse to add android.jar to the classpath.谢谢@Henning
这是我在 ant build.xml 文件中需要的内容:
Thanks @Henning
Here is what I needed in ant build.xml file:
如果您对 SDK 路径有疑问,可以手动创建一个
package-list
文件(或复制$ANDROID_HOME/docs/reference/package-list
下的文件)到你的项目。要使用相对路径,不应使用
file:/
前缀。如果将文件放入sub-directory/package-list
中,则参数将为-linkoffline http://d.android.com/reference sub-directory
If you have problems with the path to the SDK you can manually create a
package-list
file (or copy the one under$ANDROID_HOME/docs/reference/package-list
) to your project.To use a relative path you shouldn't use the
file:/
prefix. If you put the file insub-directory/package-list
the argument would be-linkoffline http://d.android.com/reference sub-directory
对于我们这些有足够勇气转向不断发展的 Android Studio 的人来说Gradle,真正有效并使事情变得更容易的事情之一是引用本地或网络上的包列表位置。例如,Julian 中的以下代码生成 javadoc 文件:
但这会在构建过程中导致警告,因为包列表 (如果曾经存在过的话),
起初我认为冗余引用/引用可能是问题所在,但包列表也不可用了
因此,在阅读了该线程的讨论后,这一行可以是更改为引用 SDK 中的本地参考目录:
它在本地查找包列表,并且不再显示警告消息。
For those of us daring enough to have switched over to the ever-evolving Android Studio & Gradle, one of the things that actually works and makes things a little easier is referring to a package-list location either locally or on the web. For example, the following code from Julian generates javadoc files:
But this resulted in a warning during the build because the package-list isn't available anymore (if it ever was) at
At first I thought maybe the redundant reference/reference was the issue, but the package-list was also unavailable at
So, after reading the discussion on this thread, that one line can be changed to refer to the local reference directory within the SDK:
It finds the package-list locally and doesn't display the warning message anymore.