如何解决build.gradle中不同版本库的错误?

时间:2017-10-12 07:10:39

标签: android android-gradle build.gradle

我正在Android中开发,并尝试实施GPS和Google地图。

build.gradle(Module: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'
}

但它显示compile 'com.android.support: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.)

但我在version-25中没有看到任何build.gradle。 我错过了什么吗? 提前谢谢。

2 个答案:

答案 0 :(得分:4)

设置

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'

答案 1 :(得分:1)

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

检查Google Play Release Notes

  

11.2中的SDK版本支持

     

将应用程序的Play服务依赖项升级到11.2.0或更高版本时,还必须更新应用程序的build.gradle,以指定至少为26(Android O)的compileSdkVersion。这不会改变您的应用运行方式。您不需要更新targetSdkVersion。如果您将compileSdkVersion更新为26,则可能会在构建中收到错误,并显示以下消息,指向Android支持库:

     

This support library should should not use a different version (25) than the compileSdkVersion (26).

     

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