How to use Gradle to generate JavaDoc in Android Studio?

后端 未结 2 1440
傲寒
傲寒 2021-02-15 11:43

I can not find any documentation on how to configure my Gradle file to create the JavaDoc for my project. I already tried some snippets from SO and blog articles but none of the

2条回答
  •  我在风中等你
    2021-02-15 12:16

    In our projects we added the following to the app's build.gradle:

    android.applicationVariants.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/");
      }
    }
    

    This will add tasks to the build of the form generateJavadoc. So let's say you have a free and a pro version of your app, this would add tasks like:

    generateFreeDebugJavadoc
    generateFreeReleaseJavadoc
    generateProDebugJavadoc
    generateProReleaseJavadoc
    

    Hope this helps

提交回复
热议问题