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

14 浏览
0 Comments

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

在升级到Android Studio 2.3后,我遇到了这个错误信息。我知道这只是一个提示,因为应用程序正常运行,但这真的很奇怪。

所有的com.android.support库都必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到了25.1.1版本和24.0.0版本。例如,com.android.support:animated-vector-drawable:25.1.1和com.android.support:mediarouter-v7:24.0.0。

\"enter

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

admin 更改状态以发布 2023年5月20日
0
0 Comments
  1. 进入文件系统中的 project/.idea/libraries 文件夹,查看有哪些库是不同的。
  2. 你需要手动包含这些具有相同版本的库到你的 build.gradle 文件中。
  3. 然后,同步你的项目。

例如:

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

0
0 Comments

您可以通过以下解决方案之一解决此问题:

更新:

自 Android Studio 3.0 起,它变得更容易了,因为它现在显示了一个更有帮助的提示,所以我们只需要按照这个提示操作即可。
例如:
1]1

所有的 com.android.support 库必须使用完全相同的版本规范(混杂使用版本可能导致运行时崩溃)。发现版本为 27.0.2 和 26.1.0,例如
com.android.support:animated-vector-drawable:27.0.2 和
com.android.support:customtabs:26.1.0

有一些库、工具和库的组合是不兼容的,或者可能导致错误。其中一种不兼容性是,编译时使用的 Android 支持库版本不是最新版本(或特别是低于目标 SDK 版本的版本)。

解决方案:
显式添加旧版本但带有新版本号的库。
在我的情况下,com.android.support:customtabs:26.1.0,因此我需要添加:

(Kotlin 构建脚本)

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

(Groovy 构建脚本)

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

即:从第二项中取出库,并使用第一项中的版本号实现它。

注意:别忘了现在按下同步按钮,让Gradle重新构建依赖关系图并查看是否还有冲突。

说明:
你可能会因为错误信息而感到困惑,因为你不使用customtabs,那么我怎么会有冲突!!
好吧..虽然你没有直接使用它,但你的一个库在内部使用了一个旧版的customtabs,所以你需要直接请求它。

如果你想知道你的哪个库负责旧版本,并可能要求作者更新他的库,请运行Gradle依赖报告,详见旧答案以了解如何。

请注意这一点。


旧答案:

CommonsWare答案启发:

运行Gradle依赖报告以查看你完整的依赖关系树。

从那儿,你将看到你的哪个库正在请求不同版本的Android支持库。
无论它要求什么,你都可以使用25.2.0版本直接请求它,或使用Gradle的其他冲突解决方法来获取相同版本。


更新:

自gradle插件版本:3.0 compile已被implementationapi替换,请参见此答案了解区别。

所以,使用以下内容代替:

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

或对于Windows cmd:

gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath

并查找冲突版本。

对我来说,在移除com.google.android.gms:play-services:10.2.0后,错误消失了。

仅包含 com.google.android.gms:play-services-location:10.2.0com.google.android.gms:play-services-maps:10.2.0,因为它们是我使用的唯一两个play服务。

我认为 gms:play-services 依赖于支持库的一些旧组件,因此我们需要显式地添加它们。


对于 AS 3.0 和早期版本。

运行:

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

示例:

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


如果有人在新的gradle插件中知道更好的方法,请告诉我。

0