简体   繁体   English

如何修复错误:找不到 com.google.gms: google-services: 3.0.0.?

[英]How to fix Error:Could not find com.google.gms: google-services: 3.0.0.?

I am trying to add firebase addmob in my app.我正在尝试在我的应用程序中添加 firebase addmob。

In build.gradle(Project) i have following code在 build.gradle(Project) 我有以下代码

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

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

In build.gradle(module)在 build.gradle(module) 中

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.myname.examp.myapp"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:design:23.0.0'
    compile 'com.google.firebase: firebase-ads: 9.0.0'
}
apply plugin: 'com.google.gms.google-services'

I have updated version of google play service and repository我已经更新了 google play 服务和存储库的版本

在此处输入图片说明

When I sync project still i am getting following error当我同步项目时仍然出现以下错误

Error:Could not find com.google.gms: google-services: 3.0.0.
Searched in the following locations:
    file:/C:/Program Files/Android/Android Studio2/gradle/m2repository/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.pom
    file:/C:/Program Files/Android/Android Studio2/gradle/m2repository/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.jar
    https://jcenter.bintray.com/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.pom
    https://jcenter.bintray.com/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.jar
Required by:
    :MyApplication:unspecified

Can some one help me how to fix this error有人可以帮我解决这个错误吗

I had similar problem, I copied the dependency from the firebase instructions and pasted in code.我遇到了类似的问题,我从 firebase 指令中复制了依赖项并粘贴到代码中。

From instructions:从说明:

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

Supposed to be:应该是:

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

Should not include any spaces.不应包含任何空格。 Silly but wasted half an hour.傻,但浪费了半个小时。

请在您的应用程序文件夹中添加google-services.json

Add the class path line in the top level gradle file.在顶级 gradle 文件中添加类路径行。 Not in the same file where you add individual dependencies.不在添加单个依赖项的同一个文件中。

Move class path dependency to project level build.gradle file as follows :将类路径依赖项移动到项目级build.gradle文件,如下所示:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        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
    }
}

and ensure that the apply plugin line after dependencies in your build.gradle file in app folder as follows并确保 app 文件夹中 build.gradle 文件中的依赖项之后的 apply plugin 行如下

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

add the classpath in the build.gradle at your project level not the one in module level.在项目级别的 build.gradle 中添加类路径,而不是模块级别的类路径。

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.1'
    classpath 'com.google.gms:google-services:3.+'

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

and then apply it in the module level.然后在模块级别应用它。

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

I had the same error.我有同样的错误。

I had solved the problem by changing我通过改变解决了这个问题

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

to

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

Maybe you need to downgrade version也许你需要降级版本

Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection Possible causes for this unexpected error include:错误:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection 无法转换为 org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection 导致此意外错误的可能原因包括:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) Gradle 的依赖缓存可能已损坏(有时会在网络连接超时后发生。)重新下载依赖项并同步项目(需要网络)
  • The state of a Gradle build process (daemon) may be corrupt. Gradle 构建进程(守护进程)的状态可能已损坏。 Stopping all Gradle daemons may solve this problem.停止所有 Gradle 守护进程可能会解决这个问题。 Stop Gradle build processes (requires restart)停止 Gradle 构建过程(需要重启)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.您的项目可能使用了第三方插件,该插件与项目中的其他插件或项目要求的 Gradle 版本不兼容。
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes. 在 Gradle 进程损坏的情况下,您还可以尝试关闭 IDE,然后杀死所有 Java 进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:将Firebase导入代码示例时,找不到com.google.gms:google-services:3.0.0 - Error:Could not find com.google.gms:google-services:3.0.0 when importing Firebase to a code sample 错误:找不到com.google.gms:google-services:3.0.0 - Error:Could not find com.google.gms:google-services:3.0.0 无法解析 com.google.gms:google-services:3.0.0 - Could not resolve com.google.gms:google-services:3.0.0 Gradle 同步失败:找不到 com.google.gms:google-services:3.0.0 - Gradle sync failed: Could not find com.google.gms:google-services:3.0.0 找不到 arguments [com.google.gms:google-services:3.0.0] 的方法 classpath() - Could not find method classpath() for arguments [com.google.gms:google-services:3.0.0] 找不到com.google.gms:google-services:9.0.0 - Could not find com.google.gms:google-services:9.0.0 找不到 com.google.gms:google-services:4.2.3 - Could not find com.google.gms:google-services:4.2.3 找不到com.google.gms:google-services:3.1.1 - Could not find com.google.gms:google-services:3.1.1 收到错误消息“找不到com.google.gms:google-services:2.0.0-alpha6。” - Getting error message “Could not find com.google.gms:google-services:2.0.0-alpha6.” 错误:(33, 0) 找不到参数的方法 classpath() [com.google.gms:google-services:3.0.1] - Error:(33, 0) Could not find method classpath() for arguments [com.google.gms:google-services:3.0.1]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM