Error when Android Studio generating JavaDoc with Gradle Script

Rick_HK
1 min readJun 3, 2020

--

Every once in a while, you may need to make JavaDoc.

You can generate JavaDoc with Gradle script, but I would recommend you to just use the one built in Android Studio instead (Tools > Generate JavaDoc)

In case you insist to use gradle script instead, here is what the script basically looks like :

android.libraryVariants.all { variant ->
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/")
options.links("http://d.android.com/reference/")
}
}

Reference from: https://stackoverflow.com/questions/29162899/how-to-use-gradle-to-generate-javadoc-in-android-studio

However, when you synchronise gradle after finish typing this code, you’ll get this error:

For Gradle version 3.5.3

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ‘:yourproject’.
> Cannot create variant ‘android-aidl’ after configuration ‘:yourproject:debugApiElements’ has been resolved

* Try:
Run with — stacktrace option to get the stack trace. Run with — info or — debug option to get more log output. Run with — scan to get full insights.

* Get more help at https://help.gradle.org

CONFIGURE FAILED in 6s
Cannot create variant ‘android-aidl’ after configuration ‘:yourproject:debugApiElements’ has been resolved

To solve this error, you can replace

classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)

with

doFirst { classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) },

The error will go away ;)

That’s it.

Happy coding.

Let me know if you find better solution or approach in the comment section below. ;)

Find me at Twitter @rick3817

--

--

Rick_HK
Rick_HK

Written by Rick_HK

Hi this is Rick from Hong Kong. I am a native iOS and Android mobile developer and also a tech enthusiast. Find me on Twitter https://twitter.com/rick3817

No responses yet