Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an AAR include transitive dependencies? [duplicate]

Right now I have a library project, say project Foo that depends on a library like OkHttp.

Now, Foo has a Maven buildstep that generates an AAR and pushes it up to a public place.

Now lets say I have project B, we'll call it Bar. Bar is an Android application, and Bar depends on Foo.

Well, I have that. However, when I make a call to a public static function in Foo from Bar that calls OkHttp, I get this message:

java.lang.NoClassDefFoundError: com.squareup.okhttp.OkUrlFactory             at com.foo.sdk.utils.OkHttpStack.<init>(OkHttpStack.java:15) 

Is such a thing possible? Or will Bar need to manually depend on OkHttp as well as any other dependencies Foo has?

like image 815
VicVu Avatar asked Sep 06 '14 07:09

VicVu


People also ask

Should I include transitive dependencies?

Don't include transitive dependencies. Exception: if you are relying on it in your code (see Z in the graph above), you must declare it. See below for proper handling in these (rare) cases.

How do you resolve transitive dependencies in gradle?

A variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.


1 Answers

It took a little while but I found what I was looking for. It just happened to be the way I was wording my searches.

This lesser-seen answer was exactly what I was looking for:

Transitive dependencies not resolved for aar library using gradle

Note that dependencies are only associated with aar libraries if they are hosted in a maven repository, in the first place, as the pom file is not included in the aar.

Essentially, I needed to add a

transitive = true 

...to the build.gradle of Bar

Example:

compile ('com.foo:FOO:1.0.0@aar'){        transitive=true } 

This way it includes all of my transitive libraries.

Note, however, that this may actually cause conflicts between dependencies (especially local ones) which can be resolved using an exclude tag.

like image 104
VicVu Avatar answered Sep 22 '22 18:09

VicVu