簡體   English   中英

如何修復錯誤:找不到 com.google.gms: google-services: 3.0.0.?

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

我正在嘗試在我的應用程序中添加 firebase addmob。

在 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
    }
}

在 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'

我已經更新了 google play 服務和存儲庫的版本

在此處輸入圖片說明

當我同步項目時仍然出現以下錯誤

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

有人可以幫我解決這個錯誤嗎

我遇到了類似的問題,我從 firebase 指令中復制了依賴項並粘貼到代碼中。

從說明:

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

應該是:

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

不應包含任何空格。 傻,但浪費了半個小時。

請在您的應用程序文件夾中添加google-services.json

在頂級 gradle 文件中添加類路徑行。 不在添加單個依賴項的同一個文件中。

將類路徑依賴項移動到項目級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
    }
}

並確保 app 文件夾中 build.gradle 文件中的依賴項之后的 apply plugin 行如下

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

在項目級別的 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
}

然后在模塊級別應用它。

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

我有同樣的錯誤。

我通過改變解決了這個問題

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

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

也許你需要降級版本

錯誤:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection 無法轉換為 org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection 導致此意外錯誤的可能原因包括:

  • Gradle 的依賴緩存可能已損壞(有時會在網絡連接超時后發生。)重新下載依賴項並同步項目(需要網絡)
  • Gradle 構建進程(守護進程)的狀態可能已損壞。 停止所有 Gradle 守護進程可能會解決這個問題。 停止 Gradle 構建過程(需要重啟)
  • 您的項目可能使用了第三方插件,該插件與項目中的其他插件或項目要求的 Gradle 版本不兼容。
在 Gradle 進程損壞的情況下,您還可以嘗試關閉 IDE,然后殺死所有 Java 進程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM