I used to use the following Gradle task in build.gradle
to build Javadocs for my Android app:
task javadoc(type: Javadoc) {
title = "My Docs v${android.defaultConfig.versionName}"
failOnError false
options.memberLevel = JavadocMemberLevel.PUBLIC
source = android.sourceSets.main.java.srcDirs
destinationDir = file("${project.rootDir}/docs/")
classpath += android.sourceSets.main.compileClasspath + android.sourceSets.main.output
// classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
// packages to exclude from the docs
exclude "com/example/README*"
// workaround for https://github.com/gradle/gradle/issues/19726 when using "exclude"/"include"
options.addStringOption("-source-path", android.sourceSets.main.java.srcDirs.join(":"))
}
However, this no longer works after upgrading from Gradle 7 and JDK 1.6 to Gradle 8 and JDK 17. I get this error:
Execution failed for task ':example:javadoc'.
> path may not be null or empty string. path=''
When I uncomment the line with the android.getBootClasspath()
, I get other errors like:
…/Example.java:21: error: package android.util does not exist
import android.util.Log;
Looking at related questions these all don't apply, or the fixes there do not work:
What can I do?
The solution seems to be to remove these lines:
classpath += android.sourceSets.main.compileClasspath + android.sourceSets.main.output
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
And instead add this:
classpath += files("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
This seems to fix the issue with JDK 17.
Hat tip to https://github.com/emanuele-f for providing this solution.