All com.android.support libraries must use the exact same version specification

前端 未结 30 2080
忘掉有多难
忘掉有多难 2020-11-21 05:10

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.andr

相关标签:
30条回答
  • 2020-11-21 05:35

    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.

    0 讨论(0)
  • 2020-11-21 05:35

    Open the external library of your project you will see that some library still using previous version although you didn't mention those library so my suggestion is just use the particular library version for those it will solve your problem.

    0 讨论(0)
  • 2020-11-21 05:38

    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:

    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'
    }
    
    0 讨论(0)
  • 2020-11-21 05:39

    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|$'
    
    0 讨论(0)
  • 2020-11-21 05:42

    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.

    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"

    0 讨论(0)
  • 2020-11-21 05:42

    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'
    
    0 讨论(0)
提交回复
热议问题