Android Studio Javadoc: Cannot find symbol

可紊 提交于 2019-11-27 00:48:33

问题


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?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!