Using ant to generate javadoc for your android project

This process describes the generation of an android project using ANT, which will generate the project and also generate the javadoc documentation

If you want to generate JavaDoc for your project directly from the command line, you can easily do it by adding some extra configuration to the ant build.xml script.

If you don’t have your ant build script in your project directory you can run the following to command to create it along with some of the necessary files required.

android update project -p <android_project_path>

The original ant build script is like this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="android_project_name" default="help">

    <property file="" />
    <property file="" />

    <property environment="env" />
    <condition property="sdk.dir" value="${env.ANDROID_HOME}">
        <isset property="env.ANDROID_HOME" />

    <loadproperties srcFile="" />

            message="sdk.dir is missing. Make sure to generate using 'android update project' or to inject it through the ANDROID_HOME environment variable."

    <import file="custom_rules.xml" optional="true" />
    <import file="${sdk.dir}/tools/ant/build.xml" />


So we need to add the following to the ant build script, you can add all this above the line

<import file="${sdk.dir}/tools/ant/build.xml" />

This is the new configuration that you need to add to the ant script

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

    description="Generate JavaDoc documentation" >

        prefix="tm" />

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

        linkoffline=" ${sdk.dir}/docs/reference"
        version="true" />

        jarfile="${bin.dir}/${tm.manifest.package}_${}_javadoc.jar" />

   depends="android_rules.clean" >

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

Now we can run the following commands

  • ant clean

    Will clean the directories for the android project and also the javadoc directory as it’s overridden in the target

  • ant javadoc

    Will generate the JavaDoc in the ${docs.dir} It will also generate a jar file with the javadoc