开发者

Generate a Javadoc for my Android project

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

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 - externa开发者_如何转开发l jars section).

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.

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.

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:

<?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. In Eclipse: project -> generate javadoc -> 3rd step under "extra javadoc options." E.g.

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


And for Ant users with no hardcoded path (for 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. I've found a workaround using maven and the javadoc plugin with the following configuration (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 libs should also be available in your local maven repository, you may use android-mvn-install script to install them.

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). By default output will be in target directory.


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

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


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.


With Maven:

Dependency on Android (installed via 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:

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

Basically you need to add this section to your project's 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.

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


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

More information is in this post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜