Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two dependencies use the same library but with different versions

It seems that I have the Picasso library, 2.4.0 but twitter also uses the 2.3.2 version of the library. My question is ... does the 2.3.2 library get downloaded alongside the newer version? Or just the 2.4.0 is downloaded and is used by twitter as well ? Should I exclude the 2.3.2 one and twitter will use the 2.4.0 automatically? Is this safe? The newer version might not be compatible with the twitter library, no?

I'm confused how I should proceed in this case. Which library should I exclude (if I can exclude one that is).

gradle -q app:dependencyInsight --dependency picasso --configuration compile

com.squareup.picasso:picasso:2.4.0 (conflict resolution)
\--- compile

com.squareup.picasso:picasso:2.3.2 -> 2.4.0
\--- com.twitter.sdk.android:tweet-ui:1.1.0
     +--- compile
     \--- com.twitter.sdk.android:twitter:1.1.1
          \--- compile

(*) - dependencies omitted (listed previously)
like image 962
AndreiBogdan Avatar asked Dec 13 '16 16:12

AndreiBogdan


People also ask

Which way should I use multiple versions of the same library?

You need to look into class loaders. It's pretty tricky, but here's a good explanation for you. You'll probably have to unload the old jar, load the new jar, run whatever the new function are, then unload that newer jar and reload the older jar.

Which dependency lets maven distinguish between multiple artifacts that are generated from the same project?

Maven can automatically bring in these artifacts, also called transitive dependencies. Version collision happens when multiple dependencies link to the same artifact, but use different versions.

Are dependencies same as libraries?

Dependency is a much more broader term than plain libraries. It can mean data, software installed, whatever. Maybe they meant to say “may depend on libraries and other dependencies”. A library is not the only thing software can depend on: configuration files, device drivers, databases, etc.


1 Answers

According to the Gradle docs:

Gradle offers the following conflict resolution strategies:

Newest: The newest version of the dependency is used. This is Gradle's default strategy, and is often an appropriate choice as long as versions are backwards-compatible.

Fail: A version conflict results in a build failure. This strategy requires all version conflicts to be resolved explicitly in the build script. See ResolutionStrategy for details on how to explicitly choose a particular version.

So Gradle is going to use Picasso 2.4.0 managing dependencies.

Will this be a problem? Possibly. You will get issues if Twitter uses method and/or signatures that have changed from going to 2.3.x to 2.4. You will get no issues if they are backwards compatible with each other.

I do now see that Twitter SDK has actually upgraded their Picasso library to 2.5.2 (The latest). If your project imports Picasso, then you can update it as well (and probably should). If it's a dependency in another module, then you may be able to update that module as well.

The other option is to downgrade Picasso to 2.3.2 or use a ResolutionStrategy to use the lower version. I wouldn't recommend this unless you have to.

like image 110
DeeV Avatar answered Oct 04 '22 00:10

DeeV