How to generate JavaDoc for Android using Gradle

So, today I’ve been trying to get JavaDoc produced and I’ve come across a number of issues. Basically, there doesn’t seem to be a single place that just says do this. There are many stackoverflow answers, some work, some don’t then if you are running JDK 1.8 then there are other issues. So, I’ll show below how to generate JavaDoc, how to call it from Gradle (because I’m new to this and it wasn’t that obvious) and how to get around the JDK 1.8 issue.

Add the following configuration to your modules build.gradle file in your project. This is the one in the app folder if you are using a standard project setup.

android.applicationVariants.all { variant ->
    task("generate${}JavaDoc", type: Javadoc) {
        description "Generates Javadoc for $"
        source = variant.javaCompile.source
        ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)

To run this on the commandline then call ./gradlew generateDebugJavaDoc or ./gradlew generateReleaseJavaDoc

If you are running JDK 1.8 on your system you will get a whole pile of lint failures from your file and since you can’t fix those then you have to work around the issue for now. This information was taken from

As you are using gradle it is simpler in my view to put this workaround in the gradle file so in the top-level project gradle file add the following.

if (JavaVersion.current().isJava8Compatible()) {
    allprojects {
        tasks.withType(Javadoc) {
            options.addStringOption('Xdoclint:none', '-quiet')

Installing Gradle on Ubuntu 14

Today I tried to install gradle using apt-get and it failed with the message

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies.
gradle : Depends: libgradle-plugins-java (= 1.4-2ubuntu1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Being a bit of a novice I had no idea how to resolve this. I tried sudo apt-get install libgradle-plugins-java but that couldn’t be resolved either.

After a bit of digging I needed to do the following to add a repository to apt-get so it could get all the dependencies.

sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle