简体   繁体   English

为我的Android项目生成一个Javadoc

[英]Generate a Javadoc for my Android project

i was hoping someone could help me in generating a javadoc for my eclipse project. 我希望有人可以帮助我为我的eclipse项目生成一个javadoc。 When i select 'Generate Javadoc' from the project menu I get lots of errors like 当我从项目菜单中选择“生成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. 每次引用Android API类的类,所以我只为不引用任何android api的类输出Javadocs。 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 1.6 lib(在构建路径 - 外部jar部分)。

Any ideas what im doing wrong? 什么想法我做错了什么?

Thanks. 谢谢。

Dori 大道

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 Manager中安装了“Android SDK文档”组件,并在Javadoc生成的第2步中选择android.jar作为参考存档,我能够为所有类生成Javadocs 。

It didn't generate links to the reference docs, but it did create docs for all of my classes. 它没有生成指向参考文档的链接,但它确实为我的所有类创建了文档。

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". 经过一些试验和错误(以及从多个Web搜索中收集到的大量建议)之后,我能够使用特定的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>

What worked for me was setting the classpath to android.jar. 对我有用的是将类路径设置为android.jar。 In Eclipse: project -> generate javadoc -> 3rd step under "extra javadoc options." 在Eclipse中:项目 - >生成javadoc - >“额外的javadoc选项”下的第3步。 Eg 例如

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

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>

Certainly there's a problem generating android javadoc from Eclipse. 当然,从Eclipse生成android javadoc存在问题。 I've found a workaround using maven and the javadoc plugin with the following configuration ( pom.xml ): 我发现使用maven和javadoc插件的解决方法具有以下配置( pom.xml ):

<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 sdk目录(在示例中为/opt/android-sdk/ )。 Android libs should also be available in your local maven repository, you may use android-mvn-install script to install them. Android库也应该在您的本地maven存储库中可用,您可以使用android-mvn-install脚本来安装它们。

Once this pom.xml is in your project root directory you will be able to Run As -> Maven build ... and configure a javadoc:javadoc goal (provided that eclipse has m2eclipse plugin installed). 一旦这个pom.xml在你的项目根目录中,你就可以运行为 - > Maven build ...并配置一个javadoc:javadoc目标(假设eclipse安装了m2eclipse插件)。 By default output will be in target directory. 默认情况下,输出将位于target目录中。

You can definitely do that with Maven. 你绝对可以用Maven做到这一点。 Ideally you can use the Maven Android Plugin for your complete build. 理想情况下,您可以使用Maven Android插件进行完整构建。 That will also allow you to use things like findbugs, checkstyle, pmd and so on. 这也可以让你使用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 文档位于项目维基以及Maven:The Complete Reference http://www.sonatype.com/books/mvnref-book/reference/android-dev.html一书中

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. 如果其他人遇到此问题:Android在ADT SDK包的r21版本中将文档样式表的名称从“android-developer-docs.css”更改为“doclava-developer-docs.css”。 Not sure exactly when the change occurred, and we just noticed the change. 不确定何时发生了变化,我们只是注意到了变化。

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>

This article by ilijamt helped 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

In Eclipse, you should add android.jar to the project classpath, either through your project properties or by editing the <path_to_your_project>/.classpath manually. 在Eclipse中,您应该通过项目属性或手动编辑<path_to_your_project>/.classpathandroid.jar添加到项目类<path_to_your_project>/.classpath

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

If you use Intellij IDEA go to Tools - Generate JavaDoc... Specify all the settings and set params: -bootclasspath [path]\\android-sdk\\platforms\\android-{version}\\android.jar -encoding UTF-8 -docencoding utf-8 -charset utf-8 如果您使用Intellij IDEA,请转到Tools - Generate JavaDoc...指定所有设置并设置参数: -bootclasspath [path]\\android-sdk\\platforms\\android-{version}\\android.jar -encoding UTF-8 -docencoding utf-8 -charset utf-8

More information is in this post . 更多信息在这篇文章中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM