問題描述
我有依賴于其他 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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!