Android: How to build AAR dependencies in APK?

I have an AAR that has dependencies A and B. Now I am adding this AAR as part of the APK dependencies.

So, in build.gradle APK I have:

compile(name:'MyAAR', ext:'aar')

      

This worked fine and built successfully. But the problem is, when I actually test the application, I got a fatal exception:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/OkHttpClient;
        at com.squareup.picasso.OkHttpDownloader.defaultOkHttpClient(OkHttpDownloader.java:31) ...

      

This is because the APK has no dependency on Picasso, but I used Picasso in my AAR.

So my question is, how do I build an AAR so that when building an APK against AAR, it automatically depends on AAR. I tried transitive = true

, didn't work.

+3


source to share


1 answer


The aar file does not contain any transitive dependencies.
Also it doesn't have a pom file that describes the dependencies. transitive=true

is the default and tells Gradle to load the dependencies specified in the pom. This is the reason because it doesn't work in your case.

In your case, you need to add other dependencies to your file build.gradle

.



An alternative is to publish the library to a maven repository (public or private). Gradle in this case with pom file can download dependencies too.

0


source







All Articles