2

I want to use location APIs with Google Play Services

This is top-level gradle file :

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

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

allprojects {
    repositories {
        jcenter()
    }
}

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

and this is my app-level gradle file :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "..."
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

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:25.0.1'
    compile 'com.android.support:design:25.0.1'
    compile 'com.android.support:recyclerview-v7:25.0.1'
    compile 'com.google.android.gms:play-services:11.4.2'
}

When I want to build the project, this error shown :

Error:(30, 13) Failed to resolve: com.google.android.gms:play-services:11.4.2
Install Repository and sync project
Show in File
Show in Project Structure dialog

I have Installed Google Play Services By Clicking on "Install Repository and Sync Project" but the error still shown

According to this documentation : https://developers.google.com/android/guides/setup I have replaced google-play-services dependency with this lines :

compile 'com.google.android.gms:play-services-location:11.4.2'
compile 'com.google.android.gms:play-services-maps:11.4.2'

When I build project, "Failed to resolve ... " error shown but when I click on "Install Repository and sync project" nothing happened !

What is the problem ? There is problem on version numbers ? or something else ?!

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Mahmoud_Mehri
  • 1,643
  • 2
  • 20
  • 38

2 Answers2

3

From what is written HERE, to use google play services from version 11.2.0 your project compileSdkVersion must be set to, at least, version 26.

When you upgrade your app’s Play services dependencies to 11.2.0 or later, your app’s build.gradle must also be updated to specify a compileSdkVersion of at least 26 (Android O). This does not change the way your app runs. You will not be required to update targetSdkVersion.

Since your project is running on version 25, the max google play service version you can import in gradle is version 11.0.

compile 'com.google.android.gms:play-services-location:11.0'
Ricardo
  • 9,136
  • 3
  • 29
  • 35
0

You need to add the following to your project level Gradle file:

allprojects { 
repositories {
 maven { url "https:// maven.google.com" }
  }
 }
//This is when you are using a version of Gradle below 4.1.

Note - if you are following this, then you also need to downgrade your play services dependency version. A better way would be to update to latest compileSDKVersion

Kartik Shandilya
  • 3,796
  • 5
  • 24
  • 42