I had the same problem (not only with android classes, but also with androidx classes), and I couldn't get "Patrick" suggestion to work. I'm using kts instead of Groovy for my build scripts and I was having a problem converting the Groovy to KTS build scripts. I never could get javadoc working using android studio "Tools/Generate Javadoc". What I did to work around the problem was to add my own Javadoc task to one of my build.gradle.kts script files. The problem of course is that javadoc is missing some classpath dependencies for android classes. That's off course what Patrik's solution is trying to address. In my case, my build scripts are a little unconventional. They usually don't include an android block in them. They get dynamically built by the inclusion of some custom plugins. That's probably the reason Patricks solution won't work for me; "android" is undefined. I also have some other requirements in that I only wanted to produce Javadoc for 4 of the 16 modules in my Projects (those 4 modules are public API that I expose). That's another reason why I add my own javadoc task. I also don't think Patrick's solution resolves the issue for androidx classes. I'll now go about explaining how my custom javadoc task work:
I added my custom javadoc task only to my root project module. Here's what the dependency block looked like:
val javadocDeps = configurations.create("javadocDeps")
dependencies {
implementation (libs.androidx.appcompat)
implementation (libs.androidx.fragment)
implementation (libs.androidx.navigation.fragment)
implementation (libs.androidx.navigation.ui)
implementation (libs.androidx.constraintlayout)
implementation(libs.androidx.drawerlayout)
implementation (project(":CoreInterfaces"))
implementation (project(":CoreInternalInterfaces"))
implementation (project(":CoreAndroidInterfaces"))
implementation (project(":CoreAndroidInternalInterfaces"))
implementation (project(":OsgiFrameworkConfiguration"))
implementation (project(":Log"))
implementation (project(":CryptoImpl"))
implementation (project(":SystemProperties"))
implementation (project(":CommunicationImpl"))
implementation (project(":CommunicationAndroidImpl"))
implementation (project(":Executor"))
implementation(project(":OsgiFramework"))
implementation(project(":OsgiInterface"))
implementation(project(":OsgiWrapper"))
implementation(project(":InstallPlanImpl_1_0_0"))
implementation (project(":InstallPlanInterfaces_1_0_0"))
javadocDeps(project(":OsgiFramework"))
javadocDeps (libs.androidx.appcompat)
javadocDeps (libs.androidx.fragment)
javadocDeps (libs.androidx.navigation.fragment)
javadocDeps (libs.androidx.navigation.ui)
javadocDeps (libs.androidx.constraintlayout)
javadocDeps (libs.androidx.drawerlayout)
}
Notice that I created a configuration called "javadocDeps".
Now here's how my custom javadoc task was defined:
tasks {
register<Javadoc>("createCoreJavadoc") {
setFailOnError(true)
val docDir: File = File(project.projectDir.parentFile.parentFile, "Doc/Core")
println("javadoc destination dir: " + docDir.absolutePath)
setDestinationDir(docDir)
var sourcepaths: FileCollection = project(":CoreInterfaces").files("src/main/java")
sourcepaths =
sourcepaths.plus(project(":CoreInternalInterfaces").files("src/main/java"))
sourcepaths = sourcepaths.plus(project(":CoreAndroidInterfaces").files("src/main/java"))
sourcepaths =
sourcepaths.plus(project(":CoreAndroidInternalInterfaces").files("src/main/java"))
sourcepaths = sourcepaths.plus(project(":OsgiInterface").files("src/main/java"))
sourcepaths =
sourcepaths.plus(project(":InstallPlanInterfaces_1_0_0").files("src/main/java"))
setSource(sourcepaths.asFileTree)
options.overview = "src/main/java/Overview.html"
android.bootClasspath.forEach{
classpath += fileTree(it)
}
val tmpDir:File = File(project.buildDir, "\\tmpAar\\")
if (tmpDir.exists()) tmpDir.delete()
tmpDir.mkdirs()
javadocDeps.forEach {
val zipFileSystem: com.phinneyridge.ZipFileSystem = ZipFileSystem(it.absolutePath,null)
if (it.name.endsWith(".aar")) {
val tmpFile:File = File(tmpDir, it.name.replace(".aar", ".jar"))
zipFileSystem.extractEntry("classes.jar", tmpFile)
} else {
classpath += fileTree(it)
}
}
classpath += fileTree(tmpDir)
//classpath += depCollection
//classpath += javadocDeps
println("classpath: " + classpath.asPath)
}
}
So you can see, 1.) I define the sourcepath of the modules that I want to produce javadoc for, and 2.) add the missing android boot classes. The next part might seem a little bit confusing. I create a temporary directory and iterate over the set of JavaDoc dependencies. If the dependency is a jar file, I just added it to the tasks classpath. If it's an aar file, I extract the classes.jar file from the aar file giving it a unique name and adding that file to my temporary directory. When that's all done, I add the temporary directory to the classpath.
This works for me and I no longer get undefined android classes and androidx classes. Notice that I had to specially treat the aar file. The javadoc task doesn't know how to handle aar files directly.