当前位置: 首页 > 知识库问答 >
问题:

如何解决构建中不同版本库的错误。格拉德尔?

年文柏
2023-03-14

我正在开发Android,并尝试实现GPS和谷歌地图。

构建。gradle(模块:app)如下所示

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        multiDexEnabled true
        applicationId "com.app.t.pro"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:26.+'
    compile 'com.google.android.gms:play-services:11.0.4'
    compile 'com.google.android.gms:play-services-maps:11.0.4'
    testCompile 'junit:junit:4.12'
}

但它在编译com时显示了错误。Android支持:appcompat-v7:26' 。错误是

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 26.1.0, 25.2.0. Examples include com.android.support:animated-vector-drawable:26.1.0 and com.android.support:mediarouter-v7:25.2.0 less... (Ctrl+F1) 
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.)

但是我在构建中没有看到任何版本25。gradle。我错过什么了吗?提前谢谢。

共有2个答案

戚修雅
2023-03-14

tl; dr您需要将Google Play库至少更新为11.2

查看Google Play发行说明

11.2中的SDK版本支持

当您将应用的Play服务依赖项升级到11.2.0或更高版本时,您的应用的build.gradle也必须更新以指定至少26(Android O)的compileSdkVersion。这不会改变您的应用运行方式。您不需要更新目标SdkVersion。如果您将compileSdkVersion更新为26,您可能会在html" target="_blank">构建中收到错误,其中包含以下提及Android支持库的消息:

此支持库不应使用与CompileSDK版本(26)不同的版本(25)

通过将支持库依赖项升级到至少26.0.0版本,可以解决此错误。

林鸿飞
2023-03-14

设置

compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'

compile 'com.google.android.gms:play-services-maps:11.4.2'
compile 'com.google.android.gms:play-services-location:11.4.2'

也去掉,

compile 'com.google.android.gms:play-services:11.4.2'
 类似资料: