How to generate javadoc for android library when it has dependencies which are also aar libraries?(当它具有也是 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当它具有也是 aar 库的依赖项时,如何为 android
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01