Gradle:下载包含aar-library的依赖项

bat*_*ope 10 android gradle android-gradle-plugin aar gradle-dependencies

我写了一个cameraBarcodeScanner内置在aar文件中的库项目.此库在其build.gradle中定义了以下依赖项:

dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 testCompile 'junit:junit:4.12'
 compile 'com.android.support:appcompat-v7:23.1.0'
 compile 'com.google.zxing:core:3.2.1'
 compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
}
Run Code Online (Sandbox Code Playgroud)

我在测试应用程序中使用该库,如下所示:

dependencies {
 compile(name: 'cameraBarcodeScanner-release', ext: 'aar')
}
Run Code Online (Sandbox Code Playgroud)

Gradle找到应用程序并能够构建它.但是,在运行时,android无法找到位于其中的类zxing-android-embedded.在我看来,gradle没有下载库项目的依赖项.我也尝试过:

dependencies {
 compile(name: 'cameraBarcodeScanner-release', ext: 'aar'){
  transitive = true
}
Run Code Online (Sandbox Code Playgroud)

但这也没有帮助.我是否必须以某种方式公开库的依赖项?您将如何使用库并使gradle下载其依赖项?

提前致谢!

Gab*_*tti 9

AAR文件不包含嵌套(或传递)的依赖关系,并且不具有其描述库所使用的依赖关系的POM文件.

这意味着,如果要使用flatDirrepo 导入aar文件,则还必须在项目中指定依赖项.

您应该使用maven存储库(您必须在私有或公共maven存储库中发布库),您将不会遇到相同的问题.
在这种情况下,gradle使用包含依赖项列表的pom文件下载依赖项.