'com.android.support:appcompat-v7:27.1.1'与com.google.android.gms:play-services-maps:15.0.1是否冲突?

时间:2018-07-05 15:46:53

标签: android gradle

我想使用Google Map,但是依赖项(com.google.android.gms:play-services-maps:15.0.1)与'com.android.support:appcompat-v7:27.1.1'冲突。谁能帮忙? 这是我的gradle文件

apply plugin: 'com.android.application'

android {
  compileSdkVersion 27
  defaultConfig {
    applicationId "com.gamecodeschool.mapso"
    minSdkVersion 18
    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(dir: 'libs', include: ['*.jar'])
  implementation 'com.android.support:appcompat-v7:27.1.0'
  implementation 'com.google.android.gms:play-services-maps:15.0.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'
}

我的顶级构建文件

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
       google()
       jcenter()
      }
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
   delete rootProject.buildDir
}

2 个答案:

答案 0 :(得分:4)

尝试添加com.google.android.gms:play-services-base:15.0.1时遇到相同的问题。

在终端中,如果通过执行./gradlew app:dependencies查找依赖关系树,则会得到以下内容:

+--- com.google.android.gms:play-services-maps:15.0.1
|    +--- com.google.android.gms:play-services-base:[15.0.1,16.0.0) -> 15.0.1
|    |    +--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1
|    |    |    \--- com.android.support:support-v4:26.1.0
|    |    |         +--- com.android.support:support-compat:26.1.0 -> 27.1.0 (*)
|    |    |         +--- com.android.support:support-media-compat:26.1.0

很明显,这会导致冲突,解决此问题的方法将改为切换到com.android.support:appcompat-v7:26.1.0

此外,您还必须将compileSdkVersiontargetSdkVersion降级。

答案 1 :(得分:1)

我的建议与@Gaurav相同,但是您可以降低播放服务中的冲突依赖性,而不必降级支持库。

implementation 'com.android.support:appcompat-v7:28.0.0'

implementation('com.google.android.gms:play-services-location:16.0.0') {
     exclude group: 'com.android.support', module:'support-v4'
}