24

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 - external jars section).

Any ideas what im doing wrong?

Thanks.

Dori

Dori
  • 18,283
  • 17
  • 74
  • 116

11 Answers11

19

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.

Erich Douglass
  • 51,744
  • 11
  • 75
  • 60
12

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>
veca
  • 149
  • 1
  • 5
  • 1
    Thanks a lot for your suggested approach. Finally I was able to generate javadoc for my android projects – Amir Sep 04 '12 at 16:36
9

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"
meh
  • 99
  • 1
  • 1
7

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>
logcat
  • 3,435
  • 1
  • 29
  • 44
3

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.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
1

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

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
0

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.

simp
  • 56
  • 3
0

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>
Risadinha
  • 16,058
  • 2
  • 88
  • 91
0

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
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
0

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.

Community
  • 1
  • 1
bocekm
  • 113
  • 7
0

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.

anil
  • 2,083
  • 21
  • 37