生成的JavaDoc与Android摇篮插件摇篮、插件、JavaDoc、Android

2023-09-12 08:45:22 作者:别拿无知当个性

我如何生成JavaDoc中使用新的摇篮构建系统的Andr​​oid项目?

How can I generate JavaDocs for an Android project using the new Gradle build system?

下面是我想出了,但它不能正常工作。

Here is what I have come up with but it doesn't work.

task generateJavadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    ext.cp = android.libraryVariants.collect { variant ->
        variant.javaCompile.classpath.files
    }
    classpath = files(ext.cp) 
}

主要的问题是,我没有得到相应的android.jar在classpath所以有的JavaDoc中的链接都没有解决。我必须找到一种方式来获得的类路径上所有必要的罐子。

The main problem is that I do not get the appropriate android.jar on the classpath so some of the links in the JavaDocs are not resolved. I have to find a way to get all the necessary jars on the classpath.

与我接过它是在方法的另一个问题收集类路径的所有版本的变种,而不是选择之一。

Another problem with the approach I took is it collects the classpaths for all the build variants, rather than selecting one.

推荐答案

我最终解决的是如下解决办法:

The solution I ended up settling on is as follows:

android.libraryVariants.all { variant ->

    task("generate${variant.name}Javadoc", type: Javadoc) {
        description "Generates Javadoc for $variant.name."
        source = variant.javaCompile.source
        ext.androidJar = "${android.plugin.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
    }

}

泽维尔Ducrohet确认这是办法做到这一点(与警告)在ADT-dev的组,https://groups.google.com/forum/#!searchin/adt-dev/javadoc/adt-dev/seRizEn8ICA/bafEvUl6mzsJ.