70

When i updated my android studio today from version 2.2.3 to 2.3 i suddenly got this error in my build.gradle on the first compile line in dependencies

(It doesnt matter which dependencie will be at the first place but it will always give me this error):

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

i have looked through my entire project and i can not find any usage of versions 24.0.0 (I have looked with ctrl + shift + F to search in entire project)

this is my build.gradle:

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionName "1.0"
        versionCode 1
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            minifyEnabled true
            shrinkResources true
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.squareup:otto:1.3.8'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.android.support:multidex:1.0.1'
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Alex
  • 789
  • 1
  • 6
  • 13
  • 4
    i had this problem too, just ignore it, or switch to beta channel of Android Studio, it should be fixed in latest release – mayosk Mar 03 '17 at 15:01
  • @Alex, did you find any better solution for this except adding customtabs and vector-drawable libraries . – Tasneem Mar 16 '17 at 05:39
  • None of the solutions below worked for me since my problem started when i got to use facebook sdk to put a Facebook Login Button in my app. It seems to depend on support:appcompat-v7:25.0.0 in some cases but i couldn't solve it... – gustavogbc Apr 01 '17 at 20:13
  • In my case it started appearing when I added com.google.android.gms:play-services:10.2.1 but disappeared when I targeted the particular google play service that was needed – N.M Apr 09 '17 at 07:24

13 Answers13

63

To elaborate on the accepted answer, proper dependency resolution for the support library case is as follows:

Don't just add transitive dependencies as direct dependencies to force their versions; this is semantically the wrong thing to do (if you ever remove the dependency that brought in the transitive dependency, you now have a leftover dependency you're not actually using).

Do the following:

In your root build.gradle, you should already have

ext {
    supportlib_version = '27.1.1'
    ...
}

and be using this property in your e.g. app/build.gradle like

dependencies {
    implementation "com.android.support:appcompat-v7:$supportlib_version"
    implementation "com.android.support:recyclerview-v7:$supportlib_version"
    ...
}

Now, in your root build.gradle, have

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "$supportlib_version"
            }
        }
    }
}

that is, in every module and every configuration, when resolving dependencies, if it's a support lib (but not the multidex ones (there may be more exceptions)), force the version to your standardized support lib version.


Now in the age of jetpack and jetifier, it appears prudent to employ a variation (assuming you have migrated to the androidx versions):

Your e.g. app/build.gradle will now contain androidx dependencies, but libraries you use may still transitively pull in supportlib dependencies, which you still want on the same version (namely, 28.0.0) so that they can get properly jetified at build time.

So keep the root build.gradle parts as is, using 28.0.0 for the supportlib_version.

Jule
  • 871
  • 5
  • 13
  • I like this answer the best though I could definitely see a case where a quirk in the support library causes a dependency expecting an earlier version to cause an issue, and it is not readily apparent what is happening. – Hugh Jeffner Mar 16 '17 at 16:53
  • True that - although that is sort of bad luck then; you'd be in the same boat if you require the same support lib dependency as that other dependency that cannot deal with the current/a later support lib version. – Jule Mar 20 '17 at 15:38
  • 1
    this is more of a better solution in the long run than patching everything – Panduka DeSilva Apr 25 '18 at 00:34
  • @Jule - is ` supportlib_version ` a reserved? Or I can name whatever I want? – RoCkDevstack Jun 21 '18 at 18:29
  • 1
    @RoCk whatever you like - although as a reader of your code, I'd expect some variation of that name for that purpose. This is a useful pattern in general when you have several artifacts using the same version of a thing - e.g. retrofit with matching adapters and converts. Then I'd also define `retrofit_version` and use it in the same way. – Jule Jun 22 '18 at 10:45
  • In my case subprojects{} not working. Just keeping configurations.all {} worked. – Nas Oct 09 '18 at 08:15
  • This works perfectly, thank you! – ChrisPrime Jan 09 '19 at 20:15
56

i have looked through my entire project and i can not find any usage of versions 24.0.0

It is coming as a transitive dependency from one of your other dependencies.

First, though, fix the other issues in your build.gradle file, as they may clear up this problem as well:

  • Do not use + for a library version. Use a specific version.

  • Do not use play-services. Use the specific dependencies for the specific pieces of the Play Services SDK that you want. play-services brings in all of Play Services, making your app much bigger than it needs to be and slowing down your build times a lot.

  • Replace com.mcxiaoke.volley with the official Volley artifact (com.android.volley:volley:1.0.0)

If none of those clear up the issue, you can run a Gradle dependency report to see what your full tree of dependencies are. From there, you will see which one of your libraries is 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 arrange to get the same version.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 20
    To see a tree of the dependencies: `./gradlew -q dependencies myModuleName:dependencies --configuration compile`. Something was using an outdated support-v4, so I added the latest to my dependencies. – Jason Hartley Mar 04 '17 at 00:16
  • running following command starts downloading gradle zip. and after that nothing happens as: "Downloading https://services.gradle.org/distributions/gradle-3.3-all.zip" – Satpal Yadav Mar 30 '17 at 11:24
  • ohh. it shown the dependencies after running command second time.:) – Satpal Yadav Mar 30 '17 at 11:50
  • 1
    Thanks it worked. I had bundle `play-services` now with specific `play-services-location` its fine – Inzimam Tariq IT Dec 07 '17 at 09:08
23

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.

You can't see the usages because its use is probably internal of another library (like google play services or squareup).

Just compile all examples that the little information window says, in your case:

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

Your

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

is version 25.2.0, 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.2.0

And do that for every example that the little information window says; in your case all the libraries that doesn't have the version 25.2.0.

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

Brandon Zamudio
  • 2,853
  • 4
  • 18
  • 34
12

Same problem happened to me. What I just did that added these two lines

compile 'com.android.support:animated-vector-drawable:25.2.0'
compile 'com.android.support:customtabs:25.2.0'

problem solved. I also deleted my previous version of gradle folder.

Abhishek Singh
  • 9,008
  • 5
  • 28
  • 53
Code Hunter
  • 133
  • 1
  • 8
8

you can add

compile 'com.android.support:customtabs:25.2.0'

and by right clicking in gradle dependency you can add the conflicting dependencies. for me it was

compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:animated-vector-drawable:25.2.0'
rookieDeveloper
  • 2,459
  • 1
  • 22
  • 44
8

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'
            }
        }
    }
}

Replace the '25.3.1' with the version of android support library that you want to use , the version must be above the version of your compileSdk version .

ezzou
  • 2,348
  • 1
  • 15
  • 16
4

I have same problem in Android studio 2.3

before: enter image description here

Then,I try:

./gradlew -q dependencies app --configuration compile

+--- project :lib
+--- com.jonathanfinerty.once:once:1.2.2
|    \--- com.android.support:support-annotations:25.3.1
+--- com.zhy:base-rvadapter:3.0.3
|    \--- com.android.support:recyclerview-v7:23.4.0
|         +--- com.android.support:support-annotations:23.4.0 -> 25.3.1
|         \--- com.android.support:support-v4:23.4.0 -> 25.3.1
|              +--- com.android.support:support-compat:25.3.1
|              |    \--- com.android.support:support-annotations:25.3.1
|              +--- com.android.support:support-media-compat:25.3.1
|              |    +--- com.android.support:support-annotations:25.3.1
|              |    \--- com.android.support:support-compat:25.3.1 (*)
|              +--- com.android.support:support-core-utils:25.3.1
|              |    +--- com.android.support:support-annotations:25.3.1
|              |    \--- com.android.support:support-compat:25.3.1 (*)
|              +--- com.android.support:support-core-ui:25.3.1
|              |    +--- com.android.support:support-annotations:25.3.1
|              |    \--- com.android.support:support-compat:25.3.1 (*)
|              \--- com.android.support:support-fragment:25.3.1
|                   +--- com.android.support:support-compat:25.3.1 (*)
|                   +--- com.android.support:support-media-compat:25.3.1 (*)
|                   +--- com.android.support:support-core-ui:25.3.1 (*)
|                   \--- com.android.support:support-core-utils:25.3.1 (*)
+--- com.squareup.okhttp3:okhttp:3.6.0
|    \--- com.squareup.okio:okio:1.11.0
+--- com.squareup.okhttp3:logging-interceptor:3.6.0
|    \--- com.squareup.okhttp3:okhttp:3.6.0 (*)
+--- com.google.code.gson:gson:2.8.0
+--- com.jakewharton:butterknife:8.4.0
|    +--- com.jakewharton:butterknife-annotations:8.4.0
|    |    \--- com.android.support:support-annotations:24.1.0 -> 25.3.1
|    \--- com.android.support:support-annotations:24.1.0 -> 25.3.1
+--- com.github.bumptech.glide:glide:3.7.0
+--- org.litepal.android:core:1.5.1
+--- com.orhanobut:logger:1.15
+--- com.android.support:appcompat-v7:25.3.1
|    +--- com.android.support:support-annotations:25.3.1
|    +--- com.android.support:support-v4:25.3.1 (*)
|    +--- com.android.support:support-vector-drawable:25.3.1
|    |    +--- com.android.support:support-annotations:25.3.1
|    |    \--- com.android.support:support-compat:25.3.1 (*)
|    \--- com.android.support:animated-vector-drawable:25.3.1
|         \--- com.android.support:support-vector-drawable:25.3.1 (*)

the base-rvadapter library not include 25.3.1:

com.zhy:base-rvadapter:3.0.3
|    \--- com.android.support:recyclerview-v7:23.4.0

Finally,I add a line:

compile 'com.android.support:design:25.3.1'

design include appcompat-v7,and base-rvadapter link 25.3.1.

+--- project :lib
+--- com.jonathanfinerty.once:once:1.2.2
|    \--- com.android.support:support-annotations:25.3.1
+--- com.zhy:base-rvadapter:3.0.3
|    \--- com.android.support:recyclerview-v7:23.4.0 -> 25.3.1
|         +--- com.android.support:support-annotations:25.3.1
|         +--- com.android.support:support-compat:25.3.1
|         |    \--- com.android.support:support-annotations:25.3.1
|         \--- com.android.support:support-core-ui:25.3.1
|              +--- com.android.support:support-annotations:25.3.1
|              \--- com.android.support:support-compat:25.3.1 (*)
+--- com.squareup.okhttp3:okhttp:3.6.0
|    \--- com.squareup.okio:okio:1.11.0
+--- com.squareup.okhttp3:logging-interceptor:3.6.0
|    \--- com.squareup.okhttp3:okhttp:3.6.0 (*)
+--- com.google.code.gson:gson:2.8.0
+--- com.jakewharton:butterknife:8.4.0
|    +--- com.jakewharton:butterknife-annotations:8.4.0
|    |    \--- com.android.support:support-annotations:24.1.0 -> 25.3.1
|    \--- com.android.support:support-annotations:24.1.0 -> 25.3.1
+--- com.github.bumptech.glide:glide:3.7.0
+--- org.litepal.android:core:1.5.1
+--- com.orhanobut:logger:1.15
+--- com.android.support:appcompat-v7:25.3.1
|    +--- com.android.support:support-annotations:25.3.1
|    +--- com.android.support:support-v4:25.3.1
|    |    +--- com.android.support:support-compat:25.3.1 (*)
|    |    +--- com.android.support:support-media-compat:25.3.1
|    |    |    +--- com.android.support:support-annotations:25.3.1
|    |    |    \--- com.android.support:support-compat:25.3.1 (*)
|    |    +--- com.android.support:support-core-utils:25.3.1
|    |    |    +--- com.android.support:support-annotations:25.3.1
|    |    |    \--- com.android.support:support-compat:25.3.1 (*)
|    |    +--- com.android.support:support-core-ui:25.3.1 (*)
|    |    \--- com.android.support:support-fragment:25.3.1
|    |         +--- com.android.support:support-compat:25.3.1 (*)
|    |         +--- com.android.support:support-media-compat:25.3.1 (*)
|    |         +--- com.android.support:support-core-ui:25.3.1 (*)
|    |         \--- com.android.support:support-core-utils:25.3.1 (*)
|    +--- com.android.support:support-vector-drawable:25.3.1
|    |    +--- com.android.support:support-annotations:25.3.1
|    |    \--- com.android.support:support-compat:25.3.1 (*)
|    \--- com.android.support:animated-vector-drawable:25.3.1
|         \--- com.android.support:support-vector-drawable:25.3.1 (*)
\--- com.android.support:design:25.3.1
     +--- com.android.support:support-v4:25.3.1 (*)
     +--- com.android.support:appcompat-v7:25.3.1 (*)
     +--- com.android.support:recyclerview-v7:25.3.1 (*)
     \--- com.android.support:transition:25.3.1
          +--- com.android.support:support-annotations:25.3.1
          \--- com.android.support:support-v4:25.3.1 (*)

after:enter image description here

thearyong
  • 49
  • 3
2

Here it is pointed that adding this line will remove the error.

compile 'com.android.support:customtabs:25.2.0'
Community
  • 1
  • 1
Alex Newman
  • 1,369
  • 12
  • 34
2

Looks like Android Studio 2.3 requires to declare external dependencies explicitly. The dependencies are customtabs and palette-v7.

You would need to explicitly add the following two external dependencies/packages in build.gradle

compile 'com.android.support:customtabs:25.2.0'
compile 'com.android.support:palette-v7:25.2.0'

I think this would solve the issue.

Sujit Devkar
  • 1,195
  • 3
  • 12
  • 22
1

Try replacing compile 'com.google.android.gms:play-services:+' with the specific package(s) you are using (see this answer: https://stackoverflow.com/a/42374426/3495069)

Community
  • 1
  • 1
mVck
  • 2,910
  • 2
  • 18
  • 20
1

Remove or update the Following Dependency

 compile 'com.google.android.gms:play-services:9.6.1'

or only add the selective services like this

compile 'com.google.android.gms:play-services-fitness:10.2.4'
compile 'com.google.android.gms:play-services-wearable:10.2.4'
K Guru
  • 1,292
  • 2
  • 17
  • 36
-1

Make all the dependencies of same version or latest version in your case replace support library versions with 25.2.0 .

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 1
    This answer is completely wrong. Please correct it or delete it. – muttonUp Mar 30 '17 at 10:40
  • @muttonUp Maybe you're right (I don't know) but the "not an answer" flag is for answers that don't even try to be an answer, f.e. new questions, comments, or "thank you" responses. It's better to downvote answers if you think they miss the mark. – Gert Arnold Mar 30 '17 at 20:05
  • I solved my issue with this...that's probably the right answer for me . You to try a shot. – Neelesh Jaisinghani Mar 31 '17 at 06:51
  • @NeeleshJaisinghani com.squareup:otto latest version is 1.3.8, so how would changing its to version 25.2.0 do anything but break your code? – muttonUp Mar 31 '17 at 09:06
-2

Use specific versions instead of +. For example, 'com.google.android.gms:play-services:10.2.0'

And use specific SDKs which you are using instead of adding the entire Play-SDKs package. For example:

'com.google.android.gms:play-services-gcm:10.2.0'
'com.google.android.gms:play-services-maps:10.2.0'
'com.google.android.gms:play-services-location:10.2.0'

This helped me resolve the issue.

Pang
  • 9,564
  • 146
  • 81
  • 122
Mr.Q
  • 29
  • 2