Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve conflicts with multiple versions of the same dependencies

I've marked my dependencies to be 24.2.1 in app/build gradle file, but when i run " gradlw app:dependencies" it shows 25.1.0 as resolved.not sure how this happening as i haven't add any dependency with 25.1.0 ?is there any way i can find which library pulling the latest

  gradlw app:dependencies
    -- com.android.support:appcompat-v7:24.2.1 -> 25.1.0
       +--- com.android.support:support-annotations:25.1.0
       +--- com.android.support:support-v4:25.1.0

In Android Studio enter image description here

like image 422
Sam Avatar asked Jun 26 '17 06:06

Sam


Video Answer


1 Answers

When this happen it's because another library you are using is pulling in other versions of the same dependencies.

You need to figure out your dependency tree with the command

./gradlew app:dependencies

to execute in the Android Studio terminal.

Then you need to scroll up the terminal window until you find the dependencies tree, check for some nested dependency coming from thirdy party libraries like in the example image below.

enter image description here

When you have found a version conflict between the third party dependency and the same dependency you declared in your buid.gradle you can exclude the pulled library and force the library to use your version:

For your problem with the support-library, you could proceed in this way:

compile ("com.example.libwithconfictdependency:library:1.0.0") {
    //this to exclude specific modules
    exclude group: 'com.android.support', module: 'support-v4'
    //or this to exclude every modules of the same package
    exclude group: 'com.android.support'
}

The problems in this case are:

  1. The library could not work because the dependency you overrided manually are not compatible with the library code
  2. You need to provide all the necessary dependencies in your build.gradle

That's up to you decide how to proceed about this.

like image 97
MatPag Avatar answered Oct 19 '22 18:10

MatPag