Generate JavaDocs with Android Gradle plugin

Solution 1:

For Android gradle plugin 1.1.2+ (com.android.tools.build:gradle:1.1.2+)

libraryVariants - does not work anymore

use:

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    destinationDir = file("../javadoc/")
    failOnError false
}

destinationDir = file("../javadoc/") - locate javadocs at root of project directory (in this way jenkins javadoc plugin could find it and show in special Document panel)

failOnError false - for suppress warnings that can cause fail build on jenkins

Solution 2:

Gradle 1.11 - Gradle Plugin 0.10.0

Replace android.plugin.sdkDirectory by android.sdkDirectory

android.libraryVariants.all { variant ->
    task("generate${variant.name}Javadoc", type: Javadoc) {
        description "Generates Javadoc for $variant.name."
        source = variant.javaCompile.source
        ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
        options.links("http://docs.oracle.com/javase/7/docs/api/");
        options.links("http://d.android.com/reference/");
        exclude '**/BuildConfig.java'
        exclude '**/R.java'
    }
}