Gradle: download Dependencies of included aar-library

时间:2016-04-07 10:48:02

标签: android gradle android-gradle aar gradle-dependencies

I wrote a library-project cameraBarcodeScanner that is built into an aar file. This library has the following dependencies defined in its 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'
}

I'm using the library in a test-application like so:

dependencies {
 compile(name: 'cameraBarcodeScanner-release', ext: 'aar')
}

Gradle finds the application and is able to build it. However, on runtime, android is not able to find the classes, that are located in zxing-android-embedded. It seems to me, that gradle is not downloading the dependencies of the library-project. I also tried:

dependencies {
 compile(name: 'cameraBarcodeScanner-release', ext: 'aar'){
  transitive = true
}

But this didn't help either. Do I have to expose the library's dependencies in some way? How would you use a library and make gradle download its dependencies?

Thanks in advance!

1 个答案:

答案 0 :(得分:8)

aar 文件不包含嵌套(或transitive)依赖项,并且没有描述所使用的依赖项的pom文件库。

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

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