Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Javadoc: Cannot find symbol

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?

like image 325
SuperDeclarative Avatar asked Jan 02 '16 22:01

SuperDeclarative


1 Answers

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
    })
}
like image 123
xkor Avatar answered Oct 03 '22 12:10

xkor