使用 Android Gradle 插件生成 JavaDocs [英] Generate JavaDocs with Android Gradle plugin

查看:31
本文介绍了使用 Android Gradle 插件生成 JavaDocs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用新的 Gradle 构建系统为 Android 项目生成 JavaDoc?

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,所以 JavaDocs 中的一些链接没有解析.我必须找到一种方法来在类路径上获取所有必需的 jar.

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)
    }

}

Xavier Ducrohet 确认这是在 adt-dev 组中执行此操作的方法(有警告),https://groups.google.com/forum/#!searchin/adt-dev/javadoc/adt-dev/seRizEn8ICA/bafEvUl6mzsJ.

Xavier Ducrohet confirmed this is the way to do it (with caveats) on the adt-dev group, https://groups.google.com/forum/#!searchin/adt-dev/javadoc/adt-dev/seRizEn8ICA/bafEvUl6mzsJ.

这篇关于使用 Android Gradle 插件生成 JavaDocs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆