Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 2.3: libraries must use the exact same exact specification [duplicate]

After updating to android studio 2.3 I got this error message. I know it's just a hint as the app run normally but it's really strange.

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 25.1.1, 24.0.0. Examples include com.android.support:animated-vector-drawable:25.1.1 and com.android.support:mediarouter-v7:24.0.0

enter image description here

my gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:support-v4:25.1.1'
    compile 'com.android.support:design:25.1.1'
    compile 'com.android.support:recyclerview-v7:25.1.1'
    compile 'com.android.support:cardview-v7:25.1.1'
    compile 'com.google.android.gms:play-services-maps:10.2.0'
    compile 'com.google.android.gms:play-services:10.2.0'

    compile 'io.reactivex.rxjava2:rxjava:2.0.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    compile 'com.blankj:utilcode:1.3.6'
    compile 'com.orhanobut:logger:1.15'
    compile 'com.facebook.stetho:stetho:1.4.2'

    provided 'com.google.auto.value:auto-value:1.2'
    annotationProcessor 'com.google.auto.value:auto-value:1.2'
    annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'

    compile 'com.mikepenz:iconics-core:2.8.2@aar'
    compile('com.mikepenz:materialdrawer:5.8.1@aar') { transitive = true }
    compile 'com.mikepenz:google-material-typeface:2.2.0.3.original@aar'
    compile 'me.zhanghai.android.materialprogressbar:library:1.3.0'
    compile 'com.github.GrenderG:Toasty:1.1.1'
    compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.8.0'
    compile 'com.github.MAXDeliveryNG:slideview:1.0.0'

    compile 'com.facebook.fresco:fresco:1.0.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'

    compile 'com.google.maps.android:android-maps-utils:0.4.4'
    compile 'com.github.jd-alexander:library:1.1.0'
}
like image 837
humazed Avatar asked Feb 21 '17 17:02

humazed


18 Answers

You can solve this with one of the following solutions:

Update:

As of Android studio 3.0, it becomes much easier as it now shows a more helpful hint, so we only need to follow this hint.
for example: 1]

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.0.2, 26.1.0. Examples include com.android.support:animated-vector-drawable:27.0.2 and com.android.support:customtabs:26.1.0

there are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.)

Solution:
Add explicitly the library with the old version but with a new version number.
in my case com.android.support:customtabs:26.1.0 so I need to add:

implementation "com.android.support:customtabs:27.0.2"  

ie: Take the library from the second item, and implement it with the version number from the first.

Note: don't forget to press sync now so gradle can rebuild the dependency graph and see if there are any more conflicts.

Explanation:
you may be confused by the error message as don't use customtabs so how I have a conflict!!
well.. you didn't use it directly but one of your libraries uses an old version of customtabs internally, so you need to ask for it directly.

if you curious to know which of your libraries is responsible for the old version and maybe ask the author to update his lib, Run a Gradle dependency report, see the old answer to know how.

Note this


Old answer:

inspired by CommonsWare answer:

Run a Gradle dependency report to see what your full tree of dependencies is.

From there, you will see which one of your libraries are asking for a different version of the Android Support libraries. For whatever it is asking for, you can ask for it directly with the 25.2.0 version or use Gradle's other conflict resolution approaches to get the same versions.


Update:

As of gradle plugin version: 3.0 compile has been replaced by implementation or api see this answer for the difference.

hence use instead:

./gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath

or for windows cmd:

gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath

and search for the conflicted version.

For me, the error disappeared after removing com.google.android.gms:play-services:10.2.0

And only include com.google.android.gms:play-services-location:10.2.0 and com.google.android.gms:play-services-maps:10.2.0 as they are the only two play services that I use.

I think the gms:play-services depend on some old components of the support library, so we need to add them explicitly ourselves.


for AS 3.0 an older.

Run:

./gradlew -q dependencies <module-name>:dependencies --configuration implementation

Example:

./gradlew -q dependencies app:dependencies --configuration implementation

if someone knows a better way in the new gradle plugin please let me know.

like image 66
humazed Avatar answered Oct 13 '22 16:10

humazed


  1. Go to project/.idea/libraries folder on your file system and see which libraries are different.
  2. You will have to manually include these libraries with the same version in your build.gradle file.
  3. Then, sync your project.

E.g.:

compile 'com.android.support:appcompat-v7:25.2.0'

// Wrong library version found on 1st point
compile 'com.android.support:customtabs:25.2.0'
like image 37
João Paulo Paiva Avatar answered Oct 13 '22 15:10

João Paulo Paiva


For all cases, not just for these versions or libraries:

Pay attention to the little information window that say something about the error, it says the examples that you have to change and add.

In this case:

Found versions 25.1.1, 24.0.0. Examples include com.android.support:animated-vector-drawable:25.1.1 and com.android.support:mediarouter-v7:24.0.0

Your

com.android.support:animated-vector-drawable:25.1.1

is version 25.1.1, and your

com.android.support:mediarouter-v7:24.0.0

is version 24.0.0, so you have to add the mediarouter with the same version:

com.android.support:mediarouter-v7:25.1.1

And do that for every example that the little information window says, in this case all the libraries that doesn't have the version 25.1.1.

You have to sync the gradle after you fix the indicated library to see the next library and package that you have to change.

IMPORTANT: If you are not explicitly using one or more specified libraries and it is giving you the error, it means that is being used internally by another library, compile it explicitly anyway.

You also can use another method to see the difference of the versions of all the libraries that you are actually compiling (like run a gradle dependency report or go to your libraries files), the real objetive is compile all the libraries that you are using with the same version.

like image 39
Brandon Zamudio Avatar answered Oct 13 '22 14:10

Brandon Zamudio


The best way to solve the problem is implement all 'com.android.support:...' suggested by Android Studio

(Doesn't matter which support versions you are using – 27.1.1, 28.0.0 etc.)

Place the cursor to the error line e.g.

implementation 'com.android.support:appcompat-v7:28.0.0'

Android Studio will suggest you which 'com.android.support:...' is different version than 'com.android.support:appcompat-v7:28.0.0'

Example

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 27.1.0, 27.0.2. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:exifinterface:27.1.0

So add com.android.support:animated-vector-drawable:28.0.0 & com.android.support:exifinterface:28.0.0. Now sync gradle file.

One by one try to implement all the suggested 'com.android.support:...' until there is no error in this line implementation 'com.android.support:appcompat-v7:28.0.0'

In my case, I added

implementation 'com.android.support:appcompat-v7:28.0.0'

implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'

All these dependencies, it could be different for you.

like image 33
Adarsh Vijayan P Avatar answered Oct 13 '22 14:10

Adarsh Vijayan P


Add this to the very end of your build.gradle (Module:app):

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == 'com.android.support') {
        if (!requested.name.startsWith("multidex")) {
            details.useVersion '25.3.1'
        }
     }

   }
}

Make sure that you replace '25.3.1' with the version of the android support library that you want to use for all the dependencies , it should not be lower than your complile sdk version

than re sync gradle

like image 22
ezzou Avatar answered Oct 13 '22 15:10

ezzou


Use variables: Doing something like the following will make it easier for you to ensure that you use the same version with all libraries

dependencies {

    ext {
        support_library_version = '25.2.0'
        google_play_services_version = '10.2.0'
    }

    //#####################################################################
    //          Support Library
    //#####################################################################
    compile "com.android.support:appcompat-v7:${support_library_version}"
    compile "com.android.support:palette-v7:${support_library_version}"
    compile "com.android.support:design:${support_library_version}"

    //#####################################################################
    //          Google Play Services
    //#####################################################################
    compile "com.google.android.gms:play-services-auth:${google_play_services_version}"
    compile "com.google.android.gms:play-services-ads:${google_play_services_version}"
    compile "com.google.android.gms:play-services-analytics:${google_play_services_version}"

    //#####################################################################
    //          Firebase
    //#####################################################################
    compile "com.google.firebase:firebase-core:${google_play_services_version}"
    compile "com.google.firebase:firebase-auth:${google_play_services_version}"
    compile "com.google.firebase:firebase-messaging:${google_play_services_version}"

More information on how Google suggests that you handle this versioning can be found in this article: https://developer.android.com/studio/build/index.html#top-level

like image 32
Daniel F Avatar answered Oct 13 '22 16:10

Daniel F


I had the exact same problem after updating to Android Studio 2.3

Adding this line to dependencies solved my problem:

compile 'com.android.support:customtabs:25.2.0'
like image 30
Berat Cevik Avatar answered Oct 13 '22 16:10

Berat Cevik


A) Run gradle dependencies or ./gradlew dependencies

B) Look at your tree and figure out which of your dependencies is specifying a different support library version for a dependency you don't control.

I didn't realize that this warning also displays if the dependency is completely unused directly by your own code. In my case, Facebook specifies some support libs I wasn't using, you can see below most of those dependencies were overridden by my own specification of 25.2.0, denoted by the -> X.X.X (*) symbols. The card view and custom tabs libs weren't overridden by anyone, so I need to ask for 25.2.0 for those ones myself even though I don't use them.

+--- com.facebook.android:facebook-android-sdk:4.17.0
|    +--- com.android.support:support-v4:25.0.0 -> 25.2.0 (*)
|    +--- com.android.support:appcompat-v7:25.0.0 -> 25.2.0 (*)
|    +--- com.android.support:cardview-v7:25.0.0
|    |    \--- com.android.support:support-annotations:25.0.0 -> 25.2.0
|    +--- com.android.support:customtabs:25.0.0
|    |    +--- com.android.support:support-compat:25.0.0 -> 25.2.0 (*)
|    |    \--- com.android.support:support-annotations:25.0.0 -> 25.2.0
|    \--- com.parse.bolts:bolts-android:1.4.0 (*)

If gradle has already warned you and given you examples...

Examples include com.android.support:animated-vector-drawable:25.1.1 and com.android.support:mediarouter-v7:24.0.0

... it's even easier if you throw in some grep highlighting for the lower version since gradle dependencies can be quite verbose:

./gradlew dependencies | grep --color -E 'com.android.support:mediarouter-v7|$'
like image 28
Daniel Wilson Avatar answered Oct 13 '22 14:10

Daniel Wilson


just add this :

compile 'com.android.support:mediarouter-v7:25.2.0'

Updated for new SDK versions

compile 'com.android.support:mediarouter-v7:28.0.0-alpha3'
like image 25
Mohsen mokhtari Avatar answered Oct 13 '22 15:10

Mohsen mokhtari


As you already seen the all answers and comments above but this answer is to clear something which a new developer might not get easily.

./gradlew -q dependencies app:dependencies --configuration compile

The above line will save your life with no doubt but how to get the exact point from the result of above line.

When you get the all dependency chart or list from the above command then you have to search the conflicting version number which you are getting in your code. please see the below image.

enter image description here

in the above image you can see that 23.4.0 is creating the problem but this we not able to find in our gradle file. So now this version number(23.4.0) will save us. When we have this number then we will find this number in the result of above command result and directly import that dependency directly in our gradle file. Please see the below image to get the clear view.

you can clearly see that com.android.support:cardview-v7:23.4.0 and com.android.support:customtabs:23.4.0 are using the version which is creating the problem. Now just simply copy those line from dependency list and explicitly use in our gradle file but with the updated version link

implementation "com.android.support:cardview-v7:26.1.0" implementation "com.android.support:customtabs:26.1.0"

like image 42
anoop ghildiyal Avatar answered Oct 13 '22 16:10

anoop ghildiyal


If the same error is on appcompat

implementation 'com.android.support:appcompat-v7:27.0.1'

then adding design solved it.

implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support:design:27.0.1'

For me, adding

implementation 'de.mrmaffen:vlc-android-sdk:2.0.6'

was including appcompat-v7:23.1.1 in

.idea/libraries

without vlc, appcompat alone is enough.

like image 45
Prabs Avatar answered Oct 13 '22 15:10

Prabs


Another way to solve conflicts is just to force the correct version for all dependencies like this:

dependencies {
            configurations.all {
                resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                    if (details.requested.group == 'com.android.support' && details.requested.name == 'support-v4') {
                        details.useVersion "27.0.2"
                    }
                }
    ...
    }

https://docs.gradle.org/current/userguide/customizing_dependency_resolution_behavior.html

like image 41
Gainder Avatar answered Oct 13 '22 15:10

Gainder


Use support-v13 instead of support-v4

compile 'com.android.support:support-v13:25.2.0'
like image 26
Mehmet Hanoğlu Avatar answered Oct 13 '22 15:10

Mehmet Hanoğlu


add these in app level dependencies

implementation 'com.android.support:asynclayoutinflater:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
like image 24
Mohammad Maaz Avatar answered Oct 13 '22 16:10

Mohammad Maaz


My problem is similar to yours. Here exist an error!

compile 'com.android.support:appcompat-v7:25.3.0'

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 25.3.0, 24.0.0. Examples include 'com.android.support:animated-vector-drawable:25.3.0' and 'com.android.support:mediarouter-v7:24.0.0'

Seeing this Examples include 'com.android.support:animated-vector-drawable:25.3.0' and 'com.android.support:mediarouter-v7:24.0.0'

the just add these codes in dependencies, make sure that versions are same.

compile 'com.android.support:animated-vector-drawable:25.3.0'
compile 'com.android.support:mediarouter-v7:25.3.0'
like image 40
Yanbin Hu Avatar answered Oct 13 '22 14:10

Yanbin Hu


I got the same error after adding compile 'com.google.android.gms:play-services:10.2.4' with compile 'com.android.support:appcompat-v7:25.3.1'.

Adding animated-vector-drawable and mediarouter libs fixed the issue.

compile 'com.google.android.gms:play-services:10.2.4'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:animated-vector-drawable:25.3.1'
compile 'com.android.support:mediarouter-v7:25.3.1'
like image 28
sa_penguin Avatar answered Oct 13 '22 15:10

sa_penguin


I had this:

dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:appcompat-v7:27.1.1'
   implementation 'com.android.support:design:27.1.1'
   implementation 'com.android.support:support-v4:27.1.1'
   implementation 'com.google.firebase:firebase-auth:12.0.1'
   implementation 'com.google.firebase:firebase-firestore:12.0.1'
   implementation 'com.google.firebase:firebase-messaging:12.0.1'
   implementation 'com.google.android.gms:play-services-auth:12.0.1'
   implementation'com.facebook.android:facebook-login:[4,5)'
   implementation 'com.twitter.sdk.android:twitter:3.1.1'
   implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
   implementation 'org.jetbrains:annotations-java5:15.0'
   implementation project(':vehiclesapi')
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'com.android.support.test:runner:1.0.1'
   androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

and got this error: enter image description here

The solutions was easy - the primary dependencies were all correct so the leaves however - any third party dependencies. Removed one by one until found the culprit, and turns out to be facebook! its using version 27.0.2 of the android support libraries. I tried to add the cardview version 27.1.1 but that didn't work eithern the solution was still simple enough.

dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:appcompat-v7:27.1.1'
   implementation 'com.android.support:design:27.1.1'
   implementation 'com.android.support:support-v4:27.1.1'
   implementation 'com.google.firebase:firebase-auth:12.0.1'
   implementation 'com.google.firebase:firebase-firestore:12.0.1'
   implementation 'com.google.firebase:firebase-messaging:12.0.1'
   implementation 'com.google.android.gms:play-services-auth:12.0.1'
   implementation('com.facebook.android:facebook-login:[4,5)'){
       // contains com.android.support:v7:27.0.2, included required com.android.support.*:27.1.1 modules
    exclude group: 'com.android.support'
   }
   implementation 'com.android.support:cardview-v7:27.1.1' // to replace facebook sdk's cardview-v7:27.0.2.
   implementation 'com.twitter.sdk.android:twitter:3.1.1'
   implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
   implementation 'org.jetbrains:annotations-java5:15.0'
   implementation project(':vehiclesapi')
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'com.android.support.test:runner:1.0.1'
   androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
like image 44
Sagar Patel Avatar answered Oct 13 '22 14:10

Sagar Patel


I used these two to solve my problem after upgrading to android studio 2.3

compile 'com.android.support:animated-vector-drawable:25.0.0'
compile 'com.android.support:mediarouter-v7:25.0.0'
like image 39
Aparajita Sinha Avatar answered Oct 13 '22 15:10

Aparajita Sinha