【问题标题】:Error: Could not find com.google.gms:google-services:1.0. when adding google service plugin in build.gradle in android studio错误:找不到 com.google.gms:google-services:1.0。在 android studio 的 build.gradle 中添加谷歌服务插件时
【发布时间】:2015-08-12 04:33:10
【问题描述】:

我正在我的 android 应用程序上为 Google+ 集成 OAuth 登录,遵循 tutorial

根据教程,我应该通过添加来添加 Google Service 插件 classpath 'com.google.gms:google-services:1.0' 在我的 android 项目中对顶级 build.gradle 的依赖。

但是,当我将 gradle 与更改同步时,我看到如下错误:

错误:找不到 com.google.gms:google-services:1.0。

在以下位置搜索: 文件:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/1.0/google-services-1.0.pom 文件:/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.pom https://jcenter.bintray.com/com/google/gms/google-services/1.0/google-services-1.0.jar

在我的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()
    }
}

似乎 android studio 无法从存储库中找到 google-services 插件。

有人有同样的问题吗?或者,我错过了什么?

【问题讨论】:

  • 它不是“com.google.gms:google-services”。但在这种情况下是“com.google.gms.google-services”。

标签: java android android-studio google-login


【解决方案1】:

我今天遇到了同样的问题。在示例中,他们改用此行: classpath 'com.google.gms:google-services:1.3.0-beta1' 这行得通。

【讨论】:

  • 检查构建脚本中的存储库中是否有 jcenter()。它对我不起作用,因为我只使用了 mavenCentral()
  • 我们如何知道何时更新?例如到 1.3.0-final 还是 1.4.0?
  • 如下所述,请查看jcenter.bintray.com/com/android/tools/build/gradle 以获取最新版本。
  • 请在bintray.com/android/android-tools/…查看可用版本。请使用教程中提供的可用版本
  • 最好导入特定的 API,在本例中为 compile 'com.google.android.gms:play-services-plus:8.1.0'。不会导入健身、可穿戴、地图等不必要的API,可以看table 1 on this page
【解决方案2】:

对我来说,我必须将存储库切换到 jcenter()。我正在使用 mavenCentral 并收到此错误。当我切换到jcenter() 时,它就会拉下依赖关系。

为此,请打开您的 build.gradle 并将 mavenCentral() 的每个实例替换为 jcenter()

【讨论】:

    【解决方案3】:

    Google 更新了their guide。原来的类路径 'com.google.gms:google-services:1.0' 现在像 joluet 建议的那样读取类路径 'com.google.gms:google-services:1.3.0-beta1'。

    【讨论】:

    • 他们好像又改了。它现在只是声明:apply plugin: 'com.google.gms.google-services'
    【解决方案4】:

    Google 现已发布插件 v1.3.0

    我能够使用this 解决它:

    类路径'com.google.gms:google-services:1.3.0'

    【讨论】:

      【解决方案5】:

      我通过以下操作解决了这个问题:

      1. 在 build.gradle 中(在项目级别):

        // Top-level build file where you can add configuration options common to all sub-projects/modules.
        
        buildscript {
            repositories {
                mavenCentral()
                jcenter()
            }
            dependencies {
                classpath 'com.android.tools.build:gradle:1.3.0'
                classpath 'com.google.gms:google-services:1.5.0-beta2'
             }
        }
        
        allprojects {
            repositories {
                mavenCentral()
            }
        }
        
      2. 在 build.gradle 中(在模块级别):

        顶部添加:

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

        并在依赖项中添加:

        compile 'com.google.android.gms:play-services-analytics:8.3.0'
        

      除此之外,请确保您已更新 SDK 中的 Google Play 服务和 Google 存储库。

      【讨论】:

        【解决方案6】:

        截至 2015 年 11 月 25 日,谷歌发布了更新版本。

        尝试添加: classpath 'com.google.gms:google-services:2.0.0-alpha1'

        并且不要忘记在 buildscript 下添加jcenter() 存储库。

        谢谢。

        【讨论】:

          【解决方案7】:

          我想你忘记了 gradle 的项目级别,

          来自developers page

          将依赖项添加到您的项目级 build.gradle
          classpath 'com.google.gms:google-services:1.5.0-beta2'

          将插件添加到您的应用级 build.gradle:
          apply plugin: 'com.google.gms.google-services'

          【讨论】:

            【解决方案8】:

            Google 已更新 GCM 去检查它,你也必须更新你的 Android Studio。

            【讨论】:

              【解决方案9】:

              我建议你不要做你正在做的事情。我也这样做了(盲目关注Set up a GCM Client App on Android),但最终超过了 65K 方法限制。

              因此,您应该从 gradle 中删除以下行:

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

              现在通过简单的 gradle 导入来导入 Google Plus 的 API:

              compile 'com.google.android.gms:play-services-plus:8.1.0'
              

              【讨论】:

                【解决方案10】:

                jcenter 存储库添加到项目级别 build.gradle 对我来说很有帮助:

                buildscript {
                    repositories {
                        jcenter();
                        mavenCentral()
                    }
                

                【讨论】:

                  【解决方案11】:

                  当我遇到这个问题时,我正试图为我的 android 应用程序设置 firebase。以下屏幕截图应该可以澄清事情-

                  我想指出几件事 - 1.一旦你

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

                  此行应位于应用级 gradle 文件的底部。不知道为什么,但在顶部对我来说并没有锻炼。

                  【讨论】:

                    【解决方案12】:

                    如果您使用 Android Studio,请尝试在 IDE 中添加 google 服务。

                    1. 右键单击文件夹模块。
                    2. Developer Services 的左侧列表中选择所需的服务。
                    3. 等待同步,IDE 会自动添加 google 依赖项。
                    4. buildscript上添加classpath

                      buildscript { repositories { jcenter() } dependencies { classpath 'com.google.gms:google-services:1.3.0-beta1' } }

                    【讨论】:

                      【解决方案13】:

                      你可能错过了这一步

                      将刚刚下载的 google-services.json 文件复制到 Android Studio 项目的 app/ 或 mobile/ 目录中。打开 Android Studio 终端窗格: $ move path-to-download/google-services.json app/

                      玩得开心。

                      【讨论】:

                      • 感谢您的评论!我认为此时安装 google-service 插件确实与 google-service.json 文件有关,因为 json 文件将在插件安装后加载。换句话说,我问的是安装google-service插件的问题,而不是用插件加载配置文件。无论如何,谢谢!
                      【解决方案14】:

                      您现在需要检查当前版本,如下面的链接所示:

                      classpath 'com.google.gms:google-services:1.3.0-beta4'
                      

                      检查这个答案:

                      Update gradle version

                      【讨论】:

                        【解决方案15】:

                        在我的案例中,我们必须寻找最后一个版本:

                        dependencies {    
                            classpath 'com.google.gms:google-services:1.4.0-beta3'
                        }
                        

                        Here你可以找到版本列表。

                        【讨论】:

                          【解决方案16】:

                          我在关注instructions 在 Android Studio 中实现 GCM 客户端时遇到了类似的问题,但是,我收到的消息是:

                          错误:找不到 com.google.gms:google-services:1.3.0-beta1...

                          虽然我从未弄清楚出了什么问题,但我只是将我的源代码、资源、清单和密钥库复制到了一个新的 Android Studio 项目中。然后,我通过手动重新添加我的依赖项来编辑新项目的自动生成的 gradle 构建文件。

                          我确保不要逐字复制旧项目中的构建文件(因为错误的来源可能在它们的某个地方)。

                          这不是一个令人满意的解决方案,但它对我有用,而且花费的时间很少。

                          【讨论】:

                            【解决方案17】:

                            对我来说,在dependencies 下添加这个工作

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

                            【讨论】:

                              【解决方案18】:

                              .idea folder 中存在一个定义project's structureworkspace.xml 文件。建议你先关闭Android Studio,然后delete .idea folder再重新导入工程。 .idea 将由 IDE 再次生成。对我来说,这个解决方案有效。

                              【讨论】:

                                【解决方案19】:

                                您应该将类​​路径“com.google.gms:google-services:1.3.0-beta1”添加到具有(Project:<name of your project)(Top level build file)build.gradledependencies。希望这会有所帮助!

                                【讨论】:

                                  【解决方案20】:

                                  我最近更新到 Android Studio 2.3 并且不知何故应用插件不起作用。

                                  在那之后,我尝试了各种方法,然后当我注释掉应用程序的 build.gradle 时是什么工作:

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

                                  然后我将它添加到顶级 build.gradle(在 classpath 'com.android.tools.build:gradle:2.2.3' 下):

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

                                  然后它就起作用了。

                                  【讨论】:

                                    猜你喜欢
                                    • 2017-11-14
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 2018-09-25
                                    • 2020-11-13
                                    • 1970-01-01
                                    • 2019-08-13
                                    • 1970-01-01
                                    • 2016-06-06
                                    相关资源
                                    最近更新 更多