Android Studio Javadoc: Cannot find symbol

Issue

I’m trying to prepare and upload my Android library to Bintray and part of that process runs the following javadoc task:

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

This task is part of a larger gradle script here:
https://raw.githubusercontent.com/attwellBrian/JCenter/master/bintrayv1.gradle

When the javadoc task runs, the following problems occur:

  1. Every @NonNull and @Nullable annotation in the project reports an error of “error: cannot find symbol”
  2. Every Javadoc reference I’ve written for an Android class, like {@link Toolbar}, reports an error of “error: reference not found”

How can I correct these reference issues when generating Javadocs?

EDIT
It looks like its not all Android class links that are creating an issue, it may just be classes that come from the Android support library (which is also where the annotations come from). Does something special need to be done to link to source files in gradle dependencies?

Solution

You should also add all your dependency to the javadoc.classpath. Try this:

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

afterEvaluate {
    javadoc.classpath += files(android.libraryVariants.collect { variant ->
        variant.javaCompileProvider.get().classpath.files
    })
}

Answered By – xkor

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published