首页 > 解决方案 > build.gradle:为 sdk 版本 27 添加播放服务依赖项时出错

问题描述

添加依赖 项实现 'com.google.android.gms:play-services-location:15.0.1'后,我在依赖项实现 'com.android.support:appcompat-v7:27.1.1'上遇到错误

所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 27.1.1、26.1.0。例子包括 com.android.support:animated-vector-drawable:27.1.1 和 com.android.support:support-media-compat:26.1.0 less... (Ctrl+F1) 有一些库的组合,或者不兼容或可能导致错误的工具和库。一种这样的不兼容是使用不是最新版本的 Android 支持库版本(或者特别是低于您的 targetSdkVersion 的版本)进行编译

我想使用需要位置依赖性的“PlaceAutocompleteFragment”。我尝试使用以下方法添加位置依赖项:

文件 > 项目结构 > 依赖项 > + > 搜索位置

获得了位置版本 12.0.2,仍然抛出上述错误。我知道还有其他问题有相同的错误,但我仍然无法找出我的错误的解决方案。

构建.gradle:

apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.manish.abc"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

另外请让我知道如何找到适用于我正在使用的 api 级别的正确版本的依赖项。

标签: androidbuild.gradle

解决方案


更新

在提示中你有:

所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本27.1.1, 26.1.0。例子包括 com.android.support:animated-vector-drawable:27.1.1 和 com.android.support:support-media-compat:26.1.0 less... (Ctrl+F1) 有一些库的组合,或者不兼容或可能导致错误的工具和库。一种这样的不兼容是使用不是最新版本的 Android 支持库版本(或者特别是低于您的 targetSdkVersion 的版本)进行编译

您必须使用提示中显示的较低版本覆盖每个库,使用较高版本,例如com.android.support:support-media-compat:26.1.0(在提示中看到)

添加'com.android.support:support-media-compat:27.1.1'更高版本27.1.1而不是26.1.0

implementation 'com.android.support:support-media-compat:27.1.1'

然后你重复这个直到警告消失


推荐阅读