【问题标题】:How to solve the error of different version of libraries in build.gradle?如何解决build.gradle中不同版本库的错误?
【发布时间】:2018-03-24 00:44:28
【问题描述】:

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

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.)

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

【问题讨论】:

标签: android android-gradle-plugin build.gradle


【解决方案1】:

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

查看Google Play Release Notes

11.2 中的 SDK 版本支持

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

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

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

【讨论】:

  • 我已将 Play 服务升级到 API 26。但错误仍然存​​在。
  • Api 26 不是 Google Play 的版本
【解决方案2】:

设置

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'

【讨论】:

  • 但是当我删除compile 'com.google.android.gms:play-services:11.4.2'时会显示无法解析符号import com.google.android.gms.location.LocationServices;
猜你喜欢
  • 2011-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-11
  • 1970-01-01
  • 2016-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多