简体   繁体   中英

How to add google play services in IntelliJ IDEA 13 with gradle

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.

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.

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 (ie 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

我知道最好不要提及已编译代码的版本,但如果您不想在每次更新Google Play服务时更新您的依赖关系部分(使用SDK管理器),只需将此引用放在您的依赖项中部分:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM