Gradle: download Dependencies of included aar-libr

2020-06-03 03:44发布

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条回答
乱世女痞
2楼-- · 2020-06-03 04:12

The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.

It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.

You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.

查看更多
登录 后发表回答