Java 错误:找不到 com.google.gms:google-services:1.0。在android studio的build.gradle中添加google服务插件时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30527369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Could not find com.google.gms:google-services:1.0. when adding google service plugin in build.gradle in android studio
提问by makeasy
I am integrating OAuth login for Google+ on my android application, following the tutorial.
我正在按照教程在我的 android 应用程序上集成 Google+ 的 OAuth 登录。
According to the tutorial, I should add the Google Service plugin by adding
classpath 'com.google.gms:google-services:1.0'
dependency to top-level build.gradle
in my android project.
根据教程,我应该通过将classpath 'com.google.gms:google-services:1.0'
依赖项添加到build.gradle
我的 android 项目中的顶级 来添加 Google Service 插件
。
However, when I sync the gradle with the changes, I see the error as follows:
但是,当我将 gradle 与更改同步时,我看到如下错误:
Error:Could not find com.google.gms:google-services:1.0.
Searched in the following locations: file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/1.0/google-services-1.0.pom file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/1.0/google-services-1.0.jar https://jcenter.bintray.com/com/google/gms/google-services/1.0/google-services-1.0.pomhttps://jcenter.bintray.com/com/google/gms/google-services/1.0/google-services-1.0.jar
错误:找不到 com.google.gms:google-services:1.0。
在以下位置搜索:file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/1.0/google-services-1.0.pom file:/C:/Program文件/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/1.0/google-services-1.0.jar https://jcenter.bintray.com/com/google/gms/google-services/ 1.0/google-services-1.0.pom https://jcenter.bintray.com/com/google/gms/google-services/1.0/google-services-1.0.jar
In my build.gradle
:
在我的build.gradle
:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.google.gms:google-services:1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
It seems that the android studio is not able to find google-services plugin from repositories.
似乎 android studio 无法从存储库中找到 google-services 插件。
Does anybody have the same issue? Or, am I missing something?
有人有同样的问题吗?或者,我错过了什么?
采纳答案by Jonas Lüthke
I ran into the same issue today. In the samples they use this line instead:
classpath 'com.google.gms:google-services:1.3.0-beta1'
This works.
我今天遇到了同样的问题。在示例中,他们改用这一行:
classpath 'com.google.gms:google-services:1.3.0-beta1'
这行得通。
回答by Trung NT Nguyen
You maybe miss this step
你可能会错过这一步
Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project. Open the Android Studio Terminal pane: $ move path-to-download/google-services.json app/
将刚刚下载的 google-services.json 文件复制到 Android Studio 项目的 app/ 或 mobile/ 目录中。打开 Android Studio 终端面板: $ move path-to-download/google-services.json app/
Have fun.
玩得开心。
回答by Michael Christoff
I got a similar problem while following the instructionsfor implementing a GCM client in Android Studio, however, the message I got was :
按照在 Android Studio 中实现 GCM 客户端的说明进行操作时,我遇到了类似的问题,但是,我得到的消息是:
Error: Could not find com.google.gms:google-services:1.3.0-beta1...
错误:找不到 com.google.gms:google-services:1.3.0-beta1...
Although I never figured out what was wrong, I simply copied my sources, resources, manifest, and keystore into a new Android Studio project. I then edited the auto-generated gradle build files for the new project by manually re-adding my dependencies.
虽然我从来没有弄清楚出了什么问题,但我只是简单地将我的源、资源、清单和密钥库复制到一个新的 Android Studio 项目中。然后,我通过手动重新添加我的依赖项,为新项目编辑了自动生成的 gradle 构建文件。
I made sure not to copy over my build files from the old project verbatim (since the source of the error likely lay in them somewhere).
我确保不要从旧项目中逐字复制我的构建文件(因为错误的根源可能存在于它们的某处)。
It is not a satisfying solution, but it worked for me and it took little time.
这不是一个令人满意的解决方案,但它对我有用,而且花费的时间很少。
回答by Rui Santos
Google updated their guide. Where it was classpath 'com.google.gms:google-services:1.0' now reads classpath 'com.google.gms:google-services:1.3.0-beta1' like joluet suggested.
谷歌更新了他们的指南。类路径 'com.google.gms:google-services:1.0' 现在读取类路径 'com.google.gms:google-services:1.3.0-beta1' 就像 joluet 建议的那样。
回答by Patrick
For me I had to switch the repository to jcenter()
. I was using mavenCentral and getting this error. As soon as I switched to jcenter()
it pulled the dependency down.
对我来说,我不得不将存储库切换到jcenter()
. 我正在使用 mavenCentral 并收到此错误。我一切换到jcenter()
它就拉低了依赖关系。
To do this, open your build.gradle
and replace each instance of mavenCentral()
with jcenter()
要做到这一点,打开build.gradle
和更换的每个实例mavenCentral()
有jcenter()
回答by mangu23
You should just add classpath 'com.google.gms:google-services:1.3.0-beta1
' to dependencies
of your (Top level build file)
the build.gradle
that has the (Project:<name of your project)
. Hope this helps!
你应该只需要添加类路径“ com.google.gms:google-services:1.3.0-beta1
”到dependencies
您(Top level build file)
的build.gradle
具有(Project:<name of your project)
。希望这可以帮助!
回答by Anexon
You need to check the current version as in the link below says, by now:
您现在需要检查当前版本,如下面的链接所示:
classpath 'com.google.gms:google-services:1.3.0-beta4'
Check this answer:
检查这个答案:
回答by Arslan Anwar
回答by Sufian
I would advise you against doing what you are doing. I did it too (by following Set up a GCM Client App on Androidblindly) but ended up with exceeding 65K method limit.
我建议你不要做你正在做的事情。我也这样做了(通过盲目地在 Android 上设置 GCM 客户端应用程序),但最终超过了 65K 方法限制。
So, you should remove the following lines from your gradle:
因此,您应该从 gradle 中删除以下几行:
apply plugin: 'com.google.gms.google-services'
classpath 'com.google.gms:google-services:1.0'
Now import APIs of Google Plus with simple gradle import:
现在通过简单的 gradle 导入来导入 Google Plus 的 API:
compile 'com.google.android.gms:play-services-plus:8.1.0'
回答by MarsPeople
I think you forgotten gradle's project level,
我想你忘记了 gradle 的项目级别,
From developers page:
从开发人员页面:
Add the dependency to your project-levelbuild.gradleclasspath 'com.google.gms:google-services:1.5.0-beta2'
将依赖项添加到您的项目级build.gradleclasspath 'com.google.gms:google-services:1.5.0-beta2'
Add the plugin to your app-levelbuild.gradle:apply plugin: 'com.google.gms.google-services'
将插件添加到您的应用程序级build.gradle:apply plugin: 'com.google.gms.google-services'