当它具有也是 aar 库的依赖项时,如何为 android 库生成 javadoc?

时间:2023-02-01
本文介绍了当它具有也是 aar 库的依赖项时,如何为 android 库生成 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任务的classpath中

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?

推荐答案

由于 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.

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

上一篇:Gradle 安装有代理问题 下一篇:如何将 Gson 附加功能添加到 Android 项目?

相关文章

最新文章