为我的 Android 项目生成一个 Javadoc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2101867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:33:37  来源:igfitidea点击:

Generate a Javadoc for my Android project

javaandroidjavadoc

提问by Dori

i was hoping someone could help me in generating a javadoc for my eclipse project. When i select 'Generate Javadoc' from the project menu I get lots of errors like

我希望有人可以帮助我为我的 Eclipse 项目生成一个 javadoc。当我从项目菜单中选择“生成 Javadoc”时,我收到很多错误,例如

cannot find symbol
symbol  : class ListView

everytime a class referencing an Android API class, so i only get Javadocs outputted for the classes that do not reference any android api stuff. My app compiles and runs correctly and on the project setting the Android 1.6 lib is present (on the build path - external jars section).

每次一个类引用一个 Android API 类时,所以我只为不引用任何 android api 内容的类输出 Javadocs。我的应用程序编译并正确运行,并且在项目设置中存在 Android 1.6 lib(在构建路径 - 外部 jars 部分)。

Any ideas what im doing wrong?

任何想法我做错了什么?

Thanks.

谢谢。

Dori

采纳答案by Erich Douglass

I was able to get Javadocs generated for all my classes by making sure that I had the "Documentation for Android SDK" component installed in the Android SDK and AVD Manager, and selecting android.jar as a reference archive in step 2 of the Javadoc generation.

通过确保在 Android SDK 和 AVD 管理器中安装了“Android SDK 文档”组件,并在 Javadoc 生成的第 2 步中选择 android.jar 作为参考存档,我能够为我的所有类生成 Javadoc .

It didn't generate links to the reference docs, but it did create docs for all of my classes.

它没有生成指向参考文档的链接,但它确实为我的所有课程创建了文档。

回答by Diego Torres Milano

Certainly there's a problem generating android javadoc from Eclipse. I've found a workaround using mavenand the javadoc plugin with the following configuration (pom.xml):

当然,从 Eclipse 生成 android javadoc 存在问题。我找到了使用maven和具有以下配置 ( pom.xml)的 javadoc 插件的解决方法:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>group</groupId>
    <artifactId>artifact</artifactId>
    <version>0.0.5-SNAPSHOT</version>
    <build>
     <sourceDirectory>src</sourceDirectory>
     <plugins>
     <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-javadoc-plugin</artifactId>
     <version>2.6.1</version>
  <configuration>
  <links>
     <link>file:/opt/android-sdk/docs/reference/</link>
   </links>
  </configuration>
  </plugin>
 </plugins>
    </build>
    <dependencies>
     <dependency>
      <groupId>android</groupId>
      <artifactId>android</artifactId>
      <version>1.5</version>
      <scope>provided</scope>
     </dependency>
      </dependencies>
</project>    

adapt your android sdk directory (/opt/android-sdk/in the example). Android libs should also be available in your local maven repository, you may use android-mvn-installscript to install them.

调整您的 android sdk 目录(/opt/android-sdk/在示例中)。Android 库也应该在您本地的 maven 存储库中可用,您可以使用android-mvn-install脚本来安装它们。

Once this pom.xmlis in your project root directory you will be able to Run As -> Maven build ...and configure a javadoc:javadocgoal (provided that eclipse has m2eclipse plugin installed). By default output will be in targetdirectory.

一旦它pom.xml位于您的项目根目录中,您就可以运行为 -> Maven build ...并配置javadoc:javadoc目标(前提是 eclipse 安装了 m2eclipse 插件)。默认情况下,输出将在target目录中。

回答by Manfred Moser

You can definitely do that with Maven. Ideally you can use the Maven Android Pluginfor your complete build. That will also allow you to use things like findbugs, checkstyle, pmd and so on.

你绝对可以用 Maven 做到这一点。理想情况下,您可以使用Maven Android 插件进行完整的构建。这也将允许您使用诸如 findbugs、checkstyle、pmd 之类的东西。

Documentation is on the project wiki as well as in the book Maven: The Complete Reference http://www.sonatype.com/books/mvnref-book/reference/android-dev.html

文档在项目 wiki 以及书中 Maven: The Complete Reference http://www.sonatype.com/books/mvnref-book/reference/android-dev.html

回答by vcavanna

I was a bit stubborn, and didn't setup Maven... hopefully this post helps someone else that's in the same boat.

我有点固执,没有设置 Maven ......希望这篇文章可以帮助其他人在同一条船上。

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

经过一些试验和错误(以及从多个网络搜索中收集到的大量建议),我能够使用特定的 ANT 脚本来实现它,该脚本可以通过“Run As -> Ant Build”在 Eclipse 中运行。

I saved this file, "javadoc.xml", in the directory of my project, in parallel with the AndroidManifest.xml file.

我将这个文件“javadoc.xml”保存在我的项目目录中,与 AndroidManifest.xml 文件并行。

Here is the content of the file:

这是文件的内容:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="doc" name="api docs">
<target name="doc" description="my docs">
    <javadoc destdir="docs" doctitle="Testing the Title" verbose="on" 
        use="true" 
        classpath="C:\Android\android-sdk_r04-windows\android-sdk-windows\platforms\android-2.1\android.jar;.\libs\admob-sdk-android.jar"
        sourcepath="gen;src"
        linkoffline="http://d.android.com/reference C:\Android\android-sdk_r04-windows\android-sdk-windows\docs\reference"
        stylesheetfile="C:\Android\android-sdk_r04-windows\android-sdk-windows\docs\assets\android-developer-docs.css"
        >
    </javadoc>
</target>
</project>

回答by meh

What worked for me was setting the classpath to android.jar. In Eclipse: project -> generate javadoc -> 3rd step under "extra javadoc options." E.g.

对我有用的是将类路径设置为 android.jar。在 Eclipse 中:项目 -> 生成 javadoc -> 在“额外 javadoc 选项”下的第 3 步。例如

-classpath "C:\android-sdk-windows\platforms\android-11\android.jar"

回答by logcat

And for Ant users with no hardcoded path (for android sdk r20)

对于没有硬编码路径的 Ant 用户(适用于 android sdk r20)

<target name="javadoc" depends="-set-debug-mode,-build-setup">

    <echo>Generating javadoc</echo>

    <property name="project.target.class.path" refid="project.target.class.path"/>
    <property name="project.all.jars.path" refid="project.all.jars.path"/>

    <javadoc access="private" 
        classpath="${project.target.class.path}:${project.all.jars.path}" 
        destdir="docs" 
        packagenames="${project.app.package}.*" 
        source="1.5" sourcepath="gen:src" />
</target>

回答by simp

In case someone else runs across this issue: Android changed the name of the documentation stylesheet from 'android-developer-docs.css' to 'doclava-developer-docs.css' in the r21 verison of the ADT SDK bundle. Not sure exactly when the change occurred, and we just noticed the change.

如果其他人遇到此问题:Android 在 ADT SDK 包的 r21 版本中将文档样式表的名称从“android-developer-docs.css”更改为“doclava-developer-docs.css”。不确定变化发生的确切时间,我们只是注意到了变化。

回答by Risadinha

With Maven:

使用 Maven:

Dependency on Android (installed via Maven Android SDK Deployer):

对 Android 的依赖(通过Maven Android SDK Deployer安装):

    <dependency>
        <groupId>android</groupId>
        <artifactId>android</artifactId>
        <version>4.2.2_r2</version>
        <scope>provided</scope>
    </dependency>

Configuration of the Javadoc Maven Plugin:

Javadoc Maven 插件的配置:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
                <additionalDependencies>
                    <additionalDependency>
                        <groupId>android</groupId>
                        <artifactId>android</artifactId>
                        <version>4.2.2_r2</version>
                    </additionalDependency>
                </additionalDependencies>
            </configuration>
            <reportSets>
                <reportSet><!-- by default, id = "default" -->
                    <reports><!-- select non-aggregate reports -->
                        <report>javadoc</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>

回答by Jasper de Vries

This article by ilijamthelped me generating Javadoc for my project using Ant.

ilijamt 的这篇文章帮助我使用 Ant 为我的项目生成了 Javadoc。

Basically you need to add this section to your project's build.xml

基本上您需要将此部分添加到您的项目的 build.xml

<property name="docs.dir" location="javadoc" />
<property name="bin.dir" location="bin" />
<property name="source.dir" location="src" />
<property name="gen.dir" location="gen" />

<target
  name="javadoc"
  description="Generate JavaDoc documentation" >

  <xmlproperty
    collapseAttributes="true"
    file="AndroidManifest.xml"
    prefix="tm" />

  <mkdir dir="${docs.dir}" />

  <javadoc
    access="private"
    author="true"
    classpath="${sdk.dir}/platforms/${target}/android.jar"
    destdir="${docs.dir}"
    linkoffline="http://d.android.com/reference ${sdk.dir}/docs/reference"
    linksource="true"
    sourcepath="${source.dir};${gen.dir}"
    use="true"
    version="true" />

  <jar
    basedir="${docs.dir}"
    compress="${jar.compress}"
    jarfile="${bin.dir}/${tm.manifest.package}_${tm.manifest.android:versionName}_javadoc.jar" />
</target>

<target
  name="clean"
  depends="android_rules.clean" >

  <delete dir="${docs.dir}" />
</target>

Which allows you to run

这允许您运行

ant javadoc

回答by bocekm

In Eclipse, you should add android.jarto the project classpath, either through your project properties or by editing the <path_to_your_project>/.classpathmanually.

在 Eclipse 中,您应该android.jar通过您的项目属性或通过<path_to_your_project>/.classpath手动编辑来添加到项目类路径。

See my answer https://stackoverflow.com/a/23925003/3499937for details.

有关详细信息,请参阅我的回答https://stackoverflow.com/a/23925003/3499937