Search code examples
androidgradlejavadocandroidx

Javadoc gradle task with Androidx library


There is a task that generates Javadoc output but the problem is when we implement androidx.core.app.ActivityCompat class it causes an error. But other tasks compile with no error.

task generateJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
configurations.implementation.setCanBeResolved(true)
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + 
configurations.implementation
destinationDir = file("release/javadoc/")
failOnError false
}

tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
options.memberLevel = JavadocMemberLevel.PRIVATE
options.windowTitle("API Documentation (${project.android.defaultConfig.versionName})")
}

The errorr is :

WifiManagerUtils.java:10: error: package androidx.core.app does not exist
import androidx.core.app.ActivityCompat;

Thanks for any help


Solution

  • I have solved the issue. I think the problem is this gradle task can't get the dependecies properly. The method; classpath += configurations.implementation seems ineffective to get dependecy permissions for some libraries.

    This method gets the third-party dependecies in the right way.

    afterEvaluate {
    generateJavadoc.classpath += files(android.libraryVariants.collect { variant ->
        variant.getJavaCompileProvider().get().classpath.files
    })}