12

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!

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
battlepope
  • 290
  • 3
  • 17

1 Answers1

13

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.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Thanks for your answer. I'll try to upload it to our company's repo. – battlepope Apr 07 '16 at 12:07
  • 1
    Just wanted to give you feedback, that your answer solved the problem. After some fiddling in the libraries's build.gradle to make gradle fill the pom.xml with all needed dependencies and uploading the result to our repo, it worked! – battlepope Jun 06 '16 at 10:43
  • Yes, after I add aar via `flatDir` I can launch app with it only if I add all library depencies to app-module depencies – mohax Jul 26 '16 at 07:32
  • Is there any way to include the dependencies? – Jalpesh Aug 19 '16 at 11:54
  • @battlepope I don't think you want to do that - if you need aar then you need aar. Jar cannot replace aar in case you have any resource file that you would like to share with the rest. Example could be you have a custom control , with xml, in your library that you want to share. In that aar is the only solution. If aar needs any dependencies then that is the question which remains open or partially answered above by adding those manually. However, aar is not equal to jar. – codebased Oct 29 '16 at 02:24