Multiple versions of the same library

I have a project A that used module A1, which used the dagger v. 1.2.2. Now I would like to add to project A, module A2, which is dependent on dagger v. 2.0. But I can’t, because these two daggers are in conflict. Can I somehow use several versions of the library in different Android modules?

+5
source share
3 answers

You cannot have both.

You need to exclude conflicting libraries from dependencies:

configurations { all*.exclude group: 'com.google.android', module: 'support-v4' } dependencies { compile 'com.android.support:support-v4:13.0.0' } 

From: https://github.com/stephanenicolas/robospice/issues/161

OR

 dependencies { compile("org.gradle.test.excludes:api:1.0") { exclude module: 'shared' } } 

From: https://docs.gradle.org/current/userguide/dependency_management.html # 52.4.7

+2
source

Why do you want to keep them both? I do not think that if possible, you should go to only one library. And here you should use the latest version, since I think that if the latter is added, then the older one does not matter. Check out these links if they help you with the dagger ...

Dagger dependencies when overriding a graph with a modular module raises NoClassDefFoundError

How to use a dagger in an android library project

Dagger dependencies when overriding a graph with a modular module raises NoClassDefFoundError

+1
source

You need to exclude the library with the dagger v. 1.2.2 and allow the dagger v. 2.0. The latter will usually be backward compatible. Check out the gradle doc on how to eliminate a specific dependency. https://docs.gradle.org/current/userguide/dependency_management.html

0
source

All Articles