所有com.android.support库都必须使用完全相同的版本规范

本文翻译自:All com.android.support libraries must use the exact same version specification

After updating to android studio 2.3 I got this error message. 更新到android studio 2.3后,我收到此错误消息。 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). 所有com.android.support库都必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。 Found versions 25.1.1, 24.0.0. 找到版本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 示例包括com.android.support:animated-vector-drawable:25.1.1和com.android.support:mediarouter-v7:24.0.0

在此处输入图片说明

my gradle: 我的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'
}

#1楼

参考:https://stackoom.com/question/2rnS3/所有com-android-support库都必须使用完全相同的版本规范


#2楼

You have defined any other dependency to compile with version 24.0.0 instead of 25.1.1 . 您已经定义了任何其他依赖项,以使用版本24.0.0而不是25.1.1进行编译。 Please set all dependencies version the same as 25.1.1 . 请设置所有依赖项版本与25.1.1相同。


#3楼

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. 从Android Studio 3.0开始,它变得更加容易,因为它现在显示了一个更有用的提示,因此我们只需要遵循此提示即可。
for example: 例如: 1]

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). 所有com.android.support库都必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。 Found versions 27.0.2, 26.1.0. 找到版本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 示例包括com.android.support:animated-vector-drawable:27.0.2和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.) 一种不兼容的情况是使用不是最新版本的Android支持库版本进行编译(或者特别是低于目标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: 就我而言com.android.support:customtabs:26.1.0所以我需要添加:

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. 注意:请不要忘记立即按sync,以便gradle可以重建依赖关系图并查看是否还有更多冲突。

Explanation: 说明:
you may be confused by the error message as don't use customtabs so how I have a conflict!! 错误消息可能会使您感到困惑,因为不使用customtabs所以我会有冲突!!
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. 很好..您没有直接使用它,但是您的一个库在内部使用了旧版本的customtabs ,因此您需要直接要求它。

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. 如果您想知道哪个库是旧版本的原因,并且可能要求作者更新他的库(运行Gradle依赖性报告),请参阅旧答案以了解具体方法。

Note this 注意这个


Old answer: 旧答案:

inspired by CommonsWare answer : CommonsWare的启发答案

Run a Gradle dependency report to see what your full tree of dependencies is. 运行Gradle依赖性报告以查看完整的依赖性树是什么。

From there, you will see which one of your libraries are asking for a different version of the Android Support libraries. 从那里,您将看到您的哪个库要求使用其他版本的Android支持库。 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. 无论要求什么,您都可以直接在25.2.0版本中要求它,或者使用Gradle的其他冲突解决方法来获得相同的版本。


Update: 更新:

As of gradle plugin version: 3.0 compile has been replaced by implementation or api see this answer for the difference. 从gradle插件版本开始:3.0 compile已被implementationapi取代,请参阅此答案以了解区别。

hence use instead: 因此改用:

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

or for windows cmd: 或对于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 对我来说,删除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. 并且仅包含com.google.android.gms:play-services-location:10.2.0com.google.android.gms:play-services-maps:10.2.0因为它们是我使用的仅有的两个播放服务。

I think the gms:play-services depend on some old components of the support library, so we need to add them explicitly ourselves. 我认为gms:play-services依赖于支持库的某些旧组件,因此我们需要自己明确添加它们。


for AS 3.0 an older. 对于AS 3.0或更早的版本。

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. 如果有人知道新的Gradle插件中有更好的方法,请告诉我。


#4楼

打开项目的外部库,您会看到一些库仍在使用以前的版本,尽管您没有提到这些库,所以我的建议是仅使用特定库的版本来解决您的问题。


#5楼

  1. Go to project/.idea/libraries folder on your file system and see which libraries are different. 转到文件系统上的project/.idea/libraries文件夹,查看哪些库不同。
  2. You will have to manually include these libraries with the same version in your build.gradle file. 您将必须在build.gradle文件中手动包含具有相同版本的这些库。
  3. Then, sync your project. 然后,同步您的项目。

Eg: 例如:

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

// Wrong library version found on 1st point
compile 'com.android.support:customtabs:25.2.0'

#6楼

I had the exact same problem after updating to Android Studio 2.3 更新到Android Studio 2.3之后,我遇到了完全相同的问题

Adding this line to dependencies solved my problem: 将此行添加到依赖项解决了我的问题:

compile 'com.android.support:customtabs:25.2.0'
发布了0 篇原创文章 · 获赞 75 · 访问量 56万+

猜你喜欢

转载自blog.csdn.net/w36680130/article/details/105428834