I realize there are quite a few questions on here already about this, but they all appear to be outdated past the point of being helpful. The two most upvoted are here:
- Using gradlew
- Using Android Studio
Even for a brand new empty project on Android Studio Koala (2024.1.1) I cannot create a Javadoc with Tools–Generate Javadoc. This yields errors as documented here. This seems to have been broken for quite some time and not very high on the todo list.
Fine, so then how do I generate it with gradle as they claim is possible as a workaround?
Lets try the most upvoted answer on SO so far, i.e.
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
destinationDir = file("../javadoc/")
failOnError false
}
This will yield:
* What went wrong:
Execution failed for task ':myapplication:javadoc'.
> path may not be null or empty string. path=''
Add println("classpath=" + android.getBootClasspath().join(File.pathSeparator))
after defining source
above, and you will see the classpath is empty. It appears the project.files is defined here for Gradle 7.7 (used by default on newest Android Studio). There is claims
paths – The paths to the files. May be empty.
So the
path may not be null or empty string. path=”
error must be thrown somewhere else. Still trying to figure exactly where that error is thrown, but that specific question is tracked my related question here
So based on comments from the above mentioned question, I have reason to believe the android
object/block is defined here. If that is so, then I don’t see any link to getBootClasspath()
so I’m surprised this is not shown in the gradle error output. Android studio’s tooltip claims it resolves to com.android.build.gradle.BaseExtension
, but I see no reference to BaseExtension
in the Android Gradle Plugin API.
In fact, the only mention of getBootClasspath
I can find is here but this is some strange URL with null
in it, so trying to find this from the normal API docs seems impossible. I also cannot find if this method ever existed in the past and was deprecated or what. Looking at the source and grep -R getBootClasspath .
I see
./builder-model/src/main/java/com/android/builder/model/AndroidProject.java: Collection<String> getBootClasspath();
./gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy: return AndroidBuilder.getBootClasspath(sdkParser);
./gradle/src/main/groovy/com/android/build/gradle/internal/model/DefaultAndroidProject.java: public Collection<String> getBootClasspath() {
./builder/src/main/java/com/android/builder/AndroidBuilder.java: * {@link #getBootClasspath(SdkParser)}.
./builder/src/main/java/com/android/builder/AndroidBuilder.java: public static List<String> getBootClasspath(@NonNull SdkParser sdkParser) {
./builder/src/main/java/com/android/builder/AndroidBuilder.java: classpath.addAll(target.getBootClasspath());
./builder/src/main/java/com/android/builder/internal/FakeAndroidTarget.java: public List<String> getBootClasspath() {
./gradle-model/src/test/java/com/android/build/gradle/model/AndroidProjectTest.java: assertFalse("Non empty bootclasspath", model.getBootClasspath().isEmpty());
The only one of those that looked exposed to the API docs was ./gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy
so I looked there to find:
public List<String> getRuntimeJarList() {
SdkParser sdkParser = getLoadedSdkParser()
return AndroidBuilder.getBootClasspath(sdkParser);
}
So I tried defining my classpath as
classpath += project.files(android.getRuntimeJarList.join(File.pathSeparator))
which resulted in
* What went wrong:
A problem occurred evaluating project ':myapplication'.
> Could not get unknown property 'getRuntimeJarList' for extension 'android' of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.
Not at all the info I was seeking from that change, but happy to now know the actual resolution for android = com.android.build.gradle.internal.dsl.BaseAppModuleExtension
So I tried to find the source for that, but there is no such BaseAppModuleExtension in ./gradle/src/main/groovy/com/android/build/gradle/internal/dsl/
of the source. find . -name "BaseAppModuleExtension"
also returns empty. Now I’m lost. How can I find the definition or replacement for getBootClasspath
if the thing gradlew tells me android
is, does not exist? Furthermore, adding println("classtype: " + android.getClass())
to the task, results in classtype: class com.android.build.gradle.internal.dsl.BaseAppModuleExtension_Decorated
If this is all internal, how in the world am I supposed to know how to use it?
More fundamentally, I need to understand what classpath
is. I don’t see it as listed method in the API, but the closest thing is setClassPath
and getClassPath
. So I tried:
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath = getClasspath()
println("classpath=" + classpath.join(File.pathSeparator))
destinationDir = file("../javadoc/")
failOnError false
}
Again, classpath is empty. Ok, so apparently gradle doesn’t know the default classpath, so it likely lies within the android
block somewhere as previously hinted.
Finally, I also tried the proposed solution given here and this runs without errors (after building the project to generate the R files) but then the javadoc directory is empty with no sign of errors.
I am at a loss for where to search next. I am troubled by how difficult generating javadocs is…