4

I want to use google map, but the dependency (com.google.android.gms:play-services-maps:15.0.1) conflicts with 'com.android.support:appcompat-v7:27.1.1' .. can anyone help? here is my gradle file

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'
}

my top-level build file

    // 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
}
moumenShobakey
  • 426
  • 5
  • 14

2 Answers2

4

I faced the same issue when trying to add com.google.android.gms:play-services-base:15.0.1.

In the Terminal, if you look for the dependency tree by doing ./gradlew app:dependencies, you'd get something that includes:

+--- 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

Clearly, this causes the conflict and the way to resolve this would be switch to com.android.support:appcompat-v7:26.1.0 instead.

Also, you will have to downgrade your compileSdkVersion and targetSdkVersion.

Gaurav
  • 66
  • 4
2

I have the same suggestion as @Gaurav but instead of downgrading your support library, you can exclude a conflicting dependency from play-services.

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'
}
jj.
  • 2,210
  • 3
  • 21
  • 22