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

806

更新到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

输入图像描述

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

将以下代码添加到你的项目Build.Gradle中:subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "26.+" } } } } - Sunil Chaudhary
54个回答

3

对我来说,我通过添加compile 'com.android.support:design:<version>'解决了错误。


3

请添加以下代码行:

implementation 'com.android.support:support-v4:27.1.1'

请确保您正在使用 Android Studio 插件 3+。

输入图片描述


3
另一个可能导致此问题的原因是,如果您有这样的声明:

还有一件事,可能会导致此问题,就是如果您有这样的声明:

compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:+'

这里的+表示获取最新版本,可能比25.3.1版本更新。可以将+替换为具体版本号,例如:25.3.1如下:

compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'

它将解决这个问题。


3

只需强制所有v7和v4库使用您在依赖项之前设置的库版本即可简单地完成。

configurations.all {
                    // To resolve the conflict for com.android.databinding
                    // dependency on support-v4:21.0.3
                    resolutionStrategy.force 'com.android.support:support-v4:28.0.0'
                    resolutionStrategy.force 'com.android.support:support-v7:28.0.0'
                }

3

如果您在实施以下所有新库后仍然遇到问题。我在这个'com.android.support:appcompat-v7:27.1.0'兼容版本上遇到了上述相同的问题。

implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:mediarouter-v7:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.android.support:support-v13:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'

我刚刚替换了这个。
'com.android.support:appcompat-v7:27.1.0'

转化为这样

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

1
只需添加 implementation 'com.android.support:support-v4:27.1.0' 即可。 - matteoh

3

尝试使用完全相同版本的支持库来构建工具。

例如:

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.itechnologyeg.*******"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    } 
dependencies {
 compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:animated-vector-drawable:25.0.0'
    compile 'com.android.support:mediarouter-v7:25.0.0'
    compile 'com.android.support:recyclerview-v7:25.0.0'
    compile 'com.android.support:cardview-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'
}

2

所有的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。

通常情况下,当我们使用Google Play服务时,会出现此警告,因为它使用支持库作为依赖项。

大多数人不知道我们可以覆盖Google Play服务中使用的支持库。当我们使用以下依赖关系时:

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

这段代码隐式依赖于com.android.support:mediarouter-v7:25.1.1库。但是它与Google Play服务依赖项com.android.support:mediarouter-v7:24.0.0发生冲突。因此,我们需要通过显式使用以下库来覆盖它:

implementation "com.android.support:mediarouter-v7:25.1.1"

然后,你的依赖块将会像这样包括它们两个:
dependencies {
    implementation "com.android.support:animated-vector-drawable:25.1.1"
    implementation "com.android.support:mediarouter-v7:25.1.1"

    ...
}

1
我的问题已经解决。 添加以下最新的依赖项:implementation 'com.google.firebase:firebase-auth:16.0.4'

1
我不得不在gradle中添加以下行来消除错误,这取决于您使用的版本,与appcompat相同。
compile 'com.android.support:appcompat-v7:26+'

compile 'com.android.support:mediarouter-v7:26+'

1
使用通配符“+”来指定版本是一个不好的做法。为了能够生成可重复的构建,请始终使用精确的版本。 - Hossain Khan
不建议使用通配符版本。现在,Android Studio甚至会警告您。 - Manuel

1
在花费约5小时后,这个解决方案对我有用了。
如果您还没有,请首先将以下行添加到您的清单标签中:
xmlns:tools="http://schemas.android.com/tools"

例子:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.winanainc"
    android:versionCode="3"
    android:versionName="1.2"
    xmlns:tools="http://schemas.android.com/tools">

然后将此元标记添加到应用程序中,以覆盖您的构建工具版本,在这种情况下,例如我选择了版本25.3.1。

<application>
   ...
   ..
    <meta-data
        tools:replace="android:value"
        android:name="android.support.VERSION"
        android:value="25.3.1" />
</application>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接