与firebase 11.8.0和google-services插件3.1.2冲突

Car*_*men 2 android gradle firebase google-play-services gradle-plugin

我与firebase 11.8.0和google-services插件3.1.2存在明显冲突.构建失败,建议我使用版本11.4.2的firebase.

我的gradle构建文件的相关摘录:

build.gradle

buildscript {
    repositories {
        google()
        ...
    }
    dependencies {
        classpath 'com.google.gms:google-services:3.1.2'
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

应用build.gradle:

apply plugin: 'com.google.gms.google-services'
repositories {
    google()
    ....
}
dependencies {
    implementation "com.google.firebase:firebase-core:11.8.0"
    ....
}
Run Code Online (Sandbox Code Playgroud)

我已经正确生成了firebase app文件:

./app/src/debug/google-services.json
./app/src/release/google-services.json
Run Code Online (Sandbox Code Playgroud)

当我构建时./gradlew clean assembleDebug,构建失败并出现此错误:

> Task :app:processDebugGoogleServices FAILED
Found com.google.firebase:firebase-core:11.8.0, but version 11.4.2 is needed for the google-services plugin.


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 11.4.2.
Run Code Online (Sandbox Code Playgroud)

Car*_*men 10

解决方案是将此行移动到app 文件的底部build.gradle(它不应位于顶部):

apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

这在文档中指定:

https://firebase.google.com/docs/android/setup

然后,在您的模块Gradle文件(通常是app/build.gradle)中,添加文件底部的apply plugin行以启用Gradle插件:

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ...
  compile 'com.google.firebase:firebase-core:11.8.0'

  // Getting a "Could not find" error? Make sure you have
  // added the Google maven respository to your root build.gradle
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)