当android库具有也是aar库的依赖项时,如何为它生成javadoc? [英] How to generate javadoc for android library when it has dependencies which are also aar libraries?

查看:20
本文介绍了当android库具有也是aar库的依赖项时,如何为它生成javadoc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 android 库项目,它依赖于其他 android 库项目.我需要为库生成 javadoc,但它失败了,因为 gradle 将 javadoc 类路径放在 .aar 位置,但 javadoc 需要 .jar 文件.

I have android library project which depends on other android library projects. I need to generate javadoc for library but it fails because gradle puts to javadoc classpath path to .aar locations but javadoc expects .jar files.

简化的gradle文件:

simplified gradle file:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    configurations {
        javadocDeps
    }

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 23
        versionCode 1
        versionName "0.1.0"
    }
}

dependencies {
    compile 'com.android.support:support-v4:23.2.0'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.annimon:stream:1.0.7'
    javadocDeps 'com.android.support:support-annotations:23.2.0'
    javadocDeps 'com.nineoldandroids:library:2.4.0'
    javadocDeps 'com.android.support:support-v4:23.2.0'
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}    

task javadoc(type: Javadoc, dependsOn: explodeAars) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    classpath += configurations.javadocDeps
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}

3 种可能的解决方案:

3 solutions possible:

1) 以某种方式从它依赖的每个 aar 库添加到类路径路径 classes.jar build/intermidiates/exploded-aar/library/version/jars/classes.jar我不知道如何在 javadoc 任务中包含这些路径.

1) somehow to add to the classpath path classes.jar from every aar library it depends build/intermidiates/exploded-aar/library/version/jars/classes.jar I don't know how to include these paths in javadoc task.

2) 从 aar 文件中手动解压 classes.jar 并将它们添加到 javadoc 任务的类路径

2) manually unpack classes.jar from aar file and add them to classpath of javadoc task

3) 非常脏的 hack - 库的硬编码路径 - 但我认为这是错误的.

3) very dirty hack - hardcoded paths to library - but I think this is so WRONG.

如何使用 gradle dsl 实现 1 或 2?

How to achieve 1 or 2 with gradle dsl?

推荐答案

@rve 的解决方案现在在 Android Studio 2.3/Gradle 3.3 上被破坏了,因为 exploded-aar 不再存在(没有构建目录中的替代方法).

The solution from @rve is now broken on Android Studio 2.3 / Gradle 3.3 as the exploded-aar no longer exists (with no alternative inside the build directory).

如果你依赖的aar不是你项目中的一个模块,你需要先解压classes.jar,然后再在classpath中引用它(基本上重新创建intermediates/exploded-aar手动).

If the aar you depend on is not a module in your project, you will need first to extract the classes.jar before referencing it in the classpath (basically re-create intermediates/exploded-aar manually).

如果你依赖的 aar 只是你项目中的另一个模块,你也可以让你的 javadoc 任务依赖于该模块的编译任务并引用该模块的 intermediates/classes/release (例如,如果您使 javadoc 依赖于 assembleRelease).该解决方法的示例:https://github.com/微软/mobile-center-sdk-android/pull/345/files

If the aar you depend on is just another module in your project you can also make your javadoc task depends on the compile task of that module and reference the intermediates/classes/release of that module (if you make javadoc depends on assembleRelease for example). An example of that workaround: https://github.com/Microsoft/mobile-center-sdk-android/pull/345/files

我真的希望有人想出更好的解决方案.

I really wish someone comes up with a better solution though.

这篇关于当android库具有也是aar库的依赖项时,如何为它生成javadoc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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