升级到Google Play服务:9.0.0时出错,无法解决:com.google.android.gms:play-services-measurement:9.0.0。

125

我将我的build.gradle文件升级了

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

编译时出现了之前没有出现过的错误:

错误: 无法解析: com.google.android.gms:play-services-measurement:9.0.0 enter image description here

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

enter image description here


2
你在 SDK 管理器中更新了 Google 存储库吗? - CommonsWare
1
嗯...当我查看SDK中play-services:9.0.0的POM时,我没有看到play-services-measurement作为依赖项,并且没有play-services-measurement9.0.0版本。你是否手动请求了play-services-measurement?如果没有,请尝试清理项目,或使用带有--refresh-dependencies开关的命令行gradle构建,以尝试停止寻找play-services-measurement。总的来说,与其使用“厨房水槽”式的play-services,不如使用更专注的依赖项(你已经注释掉的那些)。 - CommonsWare
1
  1. 我的代码中没有任何请求play-services-measurement。
  2. 因为这个错误,我切换到了“厨房水槽”play-service。
  3. 我可能需要进行这个刷新操作,这是我以前从未做过的。
- Philip Herbert
1
发生了什么问题: 配置项目“:app”时出现问题。
无法解决配置“:app:_debugCompile”的所有依赖项。 找不到com.google.android.gms:play-services-measurement:9.0.0。 在以下位置搜索: https://jcenter.bintray.com/com/google/android/gms/play-services-measurement/9 .0.0/play-services-measurement-9.0.0.pom
- Philip Herbert
1
假设下面的答案没有解决你的问题,那么你需要确定是什么正在尝试加载该依赖项(特别是那个版本)。自9.0.0起,play-services不再需要它,因此必须有其他东西请求它。 - CommonsWare
显示剩余2条评论
6个回答

246

经过发现,这种方法可以解决该问题。

请在项目级Gradle中更新您的类路径:com.google.gms:google-services:2.1.0 到类路径com.google.gms:google-services:3.0.0


39
如果有人找不到它...这个更改必须在顶层的build.gradle中进行...这对我起作用了,但后来我遇到了这个错误“缺少api_key/current_key对象”,所以我不得不应用这个解决方案 https://dev59.com/-VoU5IYBdhLWcg3wk3l2#37317752。 - Javier Torón
我遇到了一个旧的错误:“属性“orientation”已经被定义”。我将google-services的classpath更新为3.0.0,并启用了GCM并添加了在google-services.json文件中生成的Server API密钥。有人能帮我吗? - cgr
1
现在错误变成了“Error:Execution failed for task ':app:processFreeDebugGoogleServices'。> 缺少api_key/current_key对象” ??? - LemonGentry
5
请问有人可以解释一下为什么这个“修复”起作用吗?我发现SO上那些只给出建议,而不指向文档或原始失败的核心原因的答案质量很低,可能会导致更多混淆。 - Tom Pace
对于那些没有理解更新点的人:它是在项目根目录的build.gradle文件中(在dependencies标签内),而不是app文件中。 :) - diogo
显示剩余3条评论

27

必需品:Android Studio和Google Play服务的最新版本

您可以按照以下步骤将插件添加到项目中,即通过更新顶级build.gradle和应用程序级别的build.gradle文件:

classpath 'com.google.gms:google-services:3.0.0'

喜欢

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

buildscript {
    repositories {
        jcenter()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'com.google.gms:google-services:3.0.0'

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

allprojects {
    repositories {
        jcenter()
        mavenLocal()
    }
}

现在,您需要为Google Play服务添加一个依赖项。在您的应用的build.gradle文件中添加以下内容:

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

最后

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "// set Yours"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"


    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'LICENSE.txt'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.google.android.gms:play-services-gcm:9.6.1'
    compile 'com.android.support:appcompat-v7:24.2.0'

}

apply plugin: 'com.google.gms.google-services'

我收到了“无法下载Google-services.jar(com.google.gms:google-services:3.0.0)”的错误信息。 - Andrew S
1
那个链接除了你提供的建议之外没有其他建议,而且链接已经过时了。自那时以来,版本号已经发生了很大变化。 - Andrew S
@AndrewS 请提供你的 build.gradle 文件。你可以将其作为问题进行询问。 - IntelliJ Amiya
@AndrewS 请检查我的编辑答案。之后执行 clean-rebuild-gradle - IntelliJ Amiya

11

GCM已被重新命名为Firebase Cloud Messaging (FCM),如果您想使用com.google.android.gms:play-services:9.0.0,请阅读本文FCM。如果要生效,请修改您的build.gradle文件以使用该插件。

buildscript {
  dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:3.0.0'
  }
}

4
我遇到了这个错误:Error:Execution failed for task ':app:processDebugGoogleServices'。> 缺少api_key/current_key对象 - Shajeel Afzal
7
@ShajeelAfzal通过生成google-service.json文件来解决这个问题。具体步骤请参考https://developers.google.com/mobile/add。 - raditya gumay
1
@IgorGanapolsky 版本3.0.0适用于Gradle插件,9.4.0适用于库。 - alvinmeimoun
在Linux中如何将com.google.android.gms更新到版本9.2.0? SDK Manager没有显示任何更新,因此我必须手动更新。 - mrid
@mrid 我来自伊朗,我只是使用代理服务器,SDK 管理器会向我显示任何更新。如果 Google 开发者限制了你的国家,请使用代理。 - Saeed Darvish
显示剩余3条评论

1

我发现最简单的方法是使用最新版本。

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'
})
//apply plugin: 'com.google.gms.google-services' //Firebase
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
compile 'com.google.firebase:firebase-auth:10.2.6'
compile 'com.google.android.gms:play-services-auth:10.2.6' //10.2.6
compile 'com.google.firebase:firebase-core:10.2.6' // used for FCM
compile 'com.google.firebase:firebase-messaging:10.2.6' // used for FCM
testCompile 'junit:junit:4.12'
//  apply plugin: 'com.google.gms.google-services'

}

解释

apply plugin: 'com.google.gms.google-services' // 在底部添加此行.

  • 首先,apply plugin: 'com.google.gms.google-services' // 在底部添加此行.
  • 然后,将以下内容添加到依赖项中

    compile 'com.google.firebase:firebase-auth:10.2.6' // 确保这是最新版本.

    compile 'com.google.android.gms:play-services-auth:10.2.6' //10.2.6 最新版

    compile 'com.google.firebase:firebase-core:10.2.6' // 用于 FCM

    compile 'com.google.firebase:firebase-messaging:10.2.6' // 用于 FCM

假设您使用的是最新的 firebase-auth 10.2.6(即今天的最新版本为2017年5月25日),但同时您正在使用 play-services-auth:9.0.0 或更低版本,那么它们都无法建立连接并显示错误。

希望这可以帮助到您。


0

当将Play服务更改为10.2.1以上的版本时,我的依赖项开始无法解析。

我发现更改以下Maven URL可以解决此问题:

maven { url 'https://raw.githubusercontent.com/onepf/OPF-mvn-repo/master/' }

maven { url 'https://github.com/onepf/OPF-mvn-repo/raw/master/' }

可能是URL的更改避免了在gradle或maven中进行缓存,从而解决了这个问题。


0
我通过将Gradle中的字符串更改为解决了这个棘手的问题。
compile 'com.google.android.gms:play-services:9.0.0' //or latest version

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接