3
votes

I want to add the google play service to my project with gradle but every time I try to build/ run I get the following error:

Gradle: A problem occurred configuring project ':BPA App'.

Could not resolve all dependencies for configuration ':BPA App:_debugCompile'. Could not find com.google.android.gms:play-services:4.2.42. Required by: BPA App:BPA App:unspecified

My build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
//    maven { url "http://dl.bintray.com/populov/maven" }

}
android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}
dependencies {
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'com.google.android.gms:play-services:4.2.+'
}

Of course I have installed google repository and other things from the SDK-Manager.

The support-v4 and support-v7 libs works fine.

I´m new in builds with gradle. Before gradle I have imported the service-lib as a module and everything works.

Hope someone can help me.

3
Did you download it in your sdk manager? - Gabriele Mariotti
Sure, it works in my IDE without gradle as a Module Lib - Adam

3 Answers

1
votes

There could be several things going on here:

  • You don't have installed the Google Play Services extra from the SDK Manager. So you can go there and install it. (Not just Google Repository, but Google Play Services itself)
  • If you got the extra installed, but Studio doesn't recognize it, maybe you're pinpointing the wrong SDK. It happens that Android Studio had its own pre-bundled SDK, so, if you got another one installed on your computer, you may be installing the extras in that one, and AS is triying to build with the one that has not the extras installed.

Check it out in Files>ProjectStructure and make sure you got the right SDK.

0
votes

To get play services I usually go for:

compile 'com.google.android.gms:play-services:4.2.+'

This will give you the latest variant of 4.2 (i.e. 4.2.highest available incremental version)


Move mavenCentral() to the top, dependencies are resolved in top down order, if that still fails remove maven { url "http://dl.bintray.com/populov/maven" } as a test

0
votes

I know that it is not the best practice not to mention the version of the compiled code but if you do not want to update your dependency section each time you update your google play services (using SDK manager), just put this reference in your dependency section:

compile 'com.google.android.gms:play-services:+'