问题
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:
- Every @NonNull and @Nullable annotation in the project reports an error of "error: cannot find symbol"
- 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?
回答1:
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.javaCompile.classpath.files
})
}
回答2:
So these error mean that JavaDoc can't link the classes which are not in the same module (without further config). If you don't care about this (ie. having hyperlinks to classes outside of the module) you could just ignore the errors with
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
See here for more info on the Javadoc Task
来源:https://stackoverflow.com/questions/34571371/android-studio-javadoc-cannot-find-symbol