【问题标题】:Plugin with id 'com.google.gms:google-services' not found [duplicate]未找到 ID 为“com.google.gms:google-services”的插件 [重复]
【发布时间】:2019-03-21 08:12:13
【问题描述】:

我正在尝试将 Firebase 添加到我的 Android 应用中,同时同步我获得的项目:

Gradle sync failed: Plugin with id 'com.google.gms:google-services' not found.

我在应用根目录中添加了依赖项,google-services.json 文件,我还在 build.gradle 顶层添加了 Maven 存储库。

1/build.gradle顶级项目文件

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

buildscript {
    ext.kotlin_version = '1.3.21'
    repositories {
        jcenter()
        google()
    }

    allprojects {
        // ...
        repositories {
            // Check that you have the following line (if not, add it):
            google()  // Google's Maven repository
            // ...
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'  // Google Services plugin

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

    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    ext {
        buildToolsVersion = "25.0.2"
        supportLibVersion = "25.3.1"
        archRoomVersion = "1.0.0-alpha1"
    }
}

2/ build.gradle // 应用级别

dependencies {
    implementation "android.arch.persistence.room:runtime:1.1.1"
    implementation "android.arch.persistence.room:compiler:1.1.1"

    implementation 'com.google.code.gson:gson:2.2.4'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.17'

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation "android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
    implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"

    implementation 'com.google.firebase:firebase-core:16.0.1'    
}

buildscript {
    ext {
        navigationVersion = '1.0.0-alpha09'
    }
}

apply plugin: 'com.google.gms:google-services'  // Google Play services Gradle plugin

知道我该怎么做吗?

【问题讨论】:

  • 确保您在 allprojects.repositories 和 repositories 块中都有所有存储库

标签: android firebase


【解决方案1】:

apply plugin 是错误的。应该是:

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

注意com.google.gmsgoogle-services 之间的.

另外,以防万一,google() 应该排在jcenter() 之前。

【讨论】:

  • 好的,我换了它们,但没有解决问题
  • 更新了我的答案。
  • 哦,我明白了。我刚刚从 firebase 文档 firebase.google.com/docs/android/setup 中复制了它。谢谢!
  • 不客气!您能否将问题标记为已回答?
猜你喜欢
  • 2019-08-13
  • 2019-05-11
  • 2019-05-11
  • 2017-02-14
  • 2021-12-22
  • 2018-09-25
  • 2020-11-13
  • 1970-01-01
相关资源
最近更新 更多