所有的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个回答

8

使用新版本的Android Studio 3.x非常简单。

只需复制小于当前版本的版本,并明确地添加与当前版本相同的版本号。

示例:

发现版本27.1.1、27.1.0等。例如:com.android.support: animated-vector-drawable:27.1.1和com.android.support: exifinterface:27.1.0

只需复制版本com.android.support:exifinterface:27.1.0并将其更改为com.android.support:exifinterface:27.1.1,使其等于您正在使用的当前版本,并将其添加到您的gradle依赖项中,如下所示。

implementation 'com.android.support:exifinterface:27.1.1'

注意:完成后不要忘记在编辑器顶部点击立即同步


8

在升级到Android Studio 2.3后,我使用了这两个来解决我的问题。

compile 'com.android.support:animated-vector-drawable:25.0.0'
compile 'com.android.support:mediarouter-v7:25.0.0'

7

在2018年的更新中,该错误已从项目结构中进行了实现。

implementation 'com.android.support:support-v13:28.0.0'

在项目模式下,可以在“外部库”中找到你的问题。在我的情况下,我使用的是版本28和外部库,我发现了“com.android.support:support-media-compat-26.0.0”,这就是错误的原因。
在实现“support v13”之后,它就可以工作了。

这个实现后,红色的下划线已经消失了。 - Truong Hieu

6

您已将其他依赖项定义为与版本24.0.0一起编译,而不是25.1.1。请设置所有依赖项版本与25.1.1相同。


我已经更新了我的答案,所有支持版本都具有相同的版本25.1.1。 - humazed

6

以下是我解决这个警告的步骤

build.gradle

android {
    compileSdkVersion ... // must same version (ex: 26)
    ...
}

dependencies {
    ...
    compile 'any com.android.support... library'  // must same version (ex: 26.0.1)
    compile 'any com.android.support... library'  // must same version (ex: 26.0.1)

    ...
    compile ('a library B which don't use 'com.android.support...' OR use SAME version of 'com.android.support'){
         // do nothing 
    }

    ...
    compile ('a library C which use DIFFERENT 'com.android.support...' (ex:27.0.1) { 
        // By default, if use don't do anything here your app will choose the higher com.android.support... for whole project (in this case it is 27.0.1)

        // If you want to use 26.0.1 use
        exclude group: 'com.android.support', module: '...' (ex module: 'appcompat-v7') 
        exclude group: 'com.android.support', module: 'another module'
        ...

        // If you want to use 27.0.1 do 
        Upgrade `compileSdkVersion` and all 'com.android.support' to 27.0.1.
        (It may be a good solution because the best practice is always use latest `compileSdkVersion`.  
        However, use 26 or 27 is base on you for example higher library may have bug)
    }
}

为了查看/验证应用程序中所有库的依赖关系,请按照以下步骤打开终端并运行./gradlew app:dependencies
如果要查看应用程序中特定库的依赖关系,请按照本教程执行以下步骤:如何在Gradle中排除特定依赖项的依赖关系
希望这可以帮助您。

6

我不得不在gradle中添加以下几行代码才能消除错误

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

6

我运行了./gradlew tasks --all,并检查了与目标版本(25.3.1)不同的依赖项。你会得到这样的结果:

app:prepareComAndroidSupportAnimatedVectorDrawable2531Library - Prepare com.android.support:animated-vector-drawable:25.3.1
app:prepareComAndroidSupportAppcompatV72531Library - Prepare com.android.support:appcompat-v7:25.3.1
app:prepareComAndroidSupportCardviewV72531Library - Prepare com.android.support:cardview-v7:25.3.1
app:prepareComAndroidSupportCustomtabs2531Library - Prepare com.android.support:customtabs:25.3.1
app:prepareComAndroidSupportDesign2531Library - Prepare com.android.support:design:25.3.1
app:prepareComAndroidSupportMediarouterV72531Library - Prepare com.android.support:mediarouter-v7:25.3.1
app:prepareComAndroidSupportPaletteV72531Library - Prepare com.android.support:palette-v7:25.3.1
app:prepareComAndroidSupportRecyclerviewV72531Library - Prepare com.android.support:recyclerview-v7:25.3.1
app:prepareComAndroidSupportSupportCompat2531Library - Prepare com.android.support:support-compat:25.3.1
app:prepareComAndroidSupportSupportCoreUi2531Library - Prepare com.android.support:support-core-ui:25.3.1
app:prepareComAndroidSupportSupportCoreUtils2531Library - Prepare com.android.support:support-core-utils:25.3.1
app:prepareComAndroidSupportSupportFragment2531Library - Prepare com.android.support:support-fragment:25.3.1
app:prepareComAndroidSupportSupportMediaCompat2531Library - Prepare com.android.support:support-media-compat:25.3.1
app:prepareComAndroidSupportSupportV42531Library - Prepare com.android.support:support-v4:25.3.1
app:prepareComAndroidSupportSupportVectorDrawable2531Library - Prepare com.android.support:support-vector-drawable:25.3.1
app:prepareComAndroidSupportTransition2531Library - Prepare com.android.support:transition:25.3.1
app:prepareComAndroidVolleyVolley100Library - Prepare com.android.volley:volley:1.0.0
app:prepareComCrashlyticsSdkAndroidAnswers1312Library - Prepare com.crashlytics.sdk.android:answers:1.3.12
app:prepareComCrashlyticsSdkAndroidBeta124Library - Prepare com.crashlytics.sdk.android:beta:1.2.4
app:prepareComCrashlyticsSdkAndroidCrashlytics267Library - Prepare com.crashlytics.sdk.android:crashlytics:2.6.7
app:prepareComCrashlyticsSdkAndroidCrashlyticsCore2316Library - Prepare com.crashlytics.sdk.android:crashlytics-core:2.3.16
app:prepareComFacebookAndroidFacebookAndroidSdk4161Library - Prepare com.facebook.android:facebook-android-sdk:4.16.1
app:prepareComGoogleAndroidGmsPlayServicesAnalytics1026Library - Prepare com.google.android.gms:play-services-analytics:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl1026Library - Prepare com.google.android.gms:play-services-analytics-impl:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesAuth1026Library - Prepare com.google.android.gms:play-services-auth:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesAuthBase1026Library - Prepare com.google.android.gms:play-services-auth-base:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesBase1026Library - Prepare com.google.android.gms:play-services-base:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesBasement1026Library - Prepare com.google.android.gms:play-services-basement:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesCast1026Library - Prepare com.google.android.gms:play-services-cast:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesLocation1026Library - Prepare com.google.android.gms:play-services-location:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesMaps1026Library - Prepare com.google.android.gms:play-services-maps:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesTagmanagerV4Impl1026Library - Prepare com.google.android.gms:play-services-tagmanager-v4-impl:10.2.6
app:prepareComGoogleAndroidGmsPlayServicesTasks1026Library - Prepare com.google.android.gms:play-services-tasks:10.2.6
app:prepareComGoogleFirebaseFirebaseAnalytics1026Library - Prepare com.google.firebase:firebase-analytics:10.2.6
app:prepareComGoogleFirebaseFirebaseAnalyticsImpl1026Library - Prepare com.google.firebase:firebase-analytics-impl:10.2.6
app:prepareComGoogleFirebaseFirebaseAppindexing1024Library - Prepare com.google.firebase:firebase-appindexing:10.2.4
app:prepareComGoogleFirebaseFirebaseCommon1026Library - Prepare com.google.firebase:firebase-common:10.2.6
app:prepareComGoogleFirebaseFirebaseCore1026Library - Prepare com.google.firebase:firebase-core:10.2.6
app:prepareComGoogleFirebaseFirebaseIid1026Library - Prepare com.google.firebase:firebase-iid:10.2.6
app:prepareComGoogleFirebaseFirebaseMessaging1026Library - Prepare com.google.firebase:firebase-messaging:10.2.6
app:prepareComMindorksPlaceholderview027Library - Prepare com.mindorks:placeholderview:0.2.7
app:prepareDebugAndroidTestDependencies
app:prepareDebugDependencies
app:prepareDebugUnitTestDependencies
app:prepareInfoHoang8fAndroidSegmented105Library - Prepare info.hoang8f:android-segmented:1.0.5
app:prepareIoFabricSdkAndroidFabric1316Library - Prepare io.fabric.sdk.android:fabric:1.3.16
app:prepareNoNordicsemiAndroidLog211Library - Prepare no.nordicsemi.android:log:2.1.1
app:prepareNoNordicsemiAndroidSupportV18Scanner100Library - Prepare no.nordicsemi.android.support.v18:scanner:1.0.0

在这种情况下,我正在针对25.3.1进行操作,但当我运行此命令时,有一些依赖项针对不同版本。诀窍是在此列表中识别针对先前版本的依赖项,并通过在Gradle中导入最新版本的依赖项来覆盖它们。

6

我有同样的问题,但是我通过添加这三行代码来解决它

implementation 'com.android.support:design:27.1.1'
implementation "com.android.support:customtabs:27.1.1"
implementation 'com.android.support:mediarouter-v7:27.1.1'

现在一切都完美地运作。


5

对我而言,这个错误是由于我导入的第三方库使用了较旧的Google支持库模块所致。我只需将它们更新到最新版本(例如在Github上检查),错误就消失了。我建议检查您在build.gradle中包含的所有非Google库是否都是最新版本。


5

我刚刚将我的Android支持库更新到(版本:44.0.0); 然后从SDK管理器中将Android SDK工具和模拟器更新到最新版本25.3.1 这解决了我的问题。


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