Ionic/Cordova FCM:任务“:processDebugGoogleServices”执行失败

Ionic/Cordova FCM: Execution failed for task ':processDebugGoogleServices'

自从我在 Ionic Project 中安装了这个 Native FCM Plugin 后,我在执行 ionic cordova android build:

时总是遇到以下错误
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
:processDebugGoogleServices
Found com.google.android.gms:play-services-base:11.0.4, but version 9.0.0 is needed for the google-services plugin.
Found com.google.android.gms:play-services-ads:11.0.4, but version 9.0.0 is needed for the google-services plugin.
:processDebugGoogleServices FAILED

BUILD FAILED

Total time: 4.046 secs
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':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 9.0.0.

我的离子信息:

cli packages:

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 3.1.5
    Cordova Platforms  : android 6.3.0 ios 4.5.4
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node : v8.1.3
    npm  : 4.6.1
    OS   : Windows 10

Misc:

    backend : pro

这是我的 /platform/android/project.properties 文件片段:

target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.google.android.gms:play-services-base:11.0.4
cordova.system.library.2=com.google.android.gms:play-services-ads:11.0.4
cordova.system.library.3=com.google.firebase:firebase-core:+
cordova.system.library.4=com.google.firebase:firebase-messaging:+
cordova.gradle.include.1=cordova-plugin-fcm/bar-FCMPlugin.gradle
cordova.gradle.include.2=phonegap-plugin-barcodescanner/bar-barcodescanner.gradle
cordova.gradle.include.3=cordova-android-play-services-gradle-release/bar-cordova-android-play-services-gradle-release.gradle

这是我的 /platform/android/build.gradle 文件的片段:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    debugCompile(project(path: "CordovaLib", configuration: "debug"))
    releaseCompile(project(path: "CordovaLib", configuration: "release"))
    compile "com.google.android.gms:play-services-base:11.0.4"
    compile "com.google.android.gms:play-services-ads:11.0.4"
    compile "com.google.firebase:firebase-core:+"
    compile "com.google.firebase:firebase-messaging:+"
    // SUB-PROJECT DEPENDENCIES END
}

我尝试了什么? 如果我将 build.gradleproject.properties 中的所有 Verisons 更改为 9.0.0 我得到这个错误:

Total time: 12.661 secs
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/FirebaseException;

如果您还需要什么,请告诉我,我会添加!

您可以使用my answer

只需编辑:

/platforms/android/cordova-plugin-fcm/blabla-FCMPlugin.gradle

将 google() 添加到存储库{}

类路径'com.android.tools.build:gradle:3.0.1'

与 /platforms/android/cordova-support-google-services/blabla-build 相同。gradle

我还使用了脚本 (gms-gradle-fix.zip) 并在 config.xml 下:

<platform name="android"> ... <hook src="scripts/gms-gradle-fix.js" type="before_prepare" />

您需要确保所有版本都相同。

cordova.system.library.1=com.google.android.gms:play-services-base:11.8.0
cordova.system.library.2=com.google.android.gms:play-services-ads:11.8.0
cordova.system.library.3=com.google.firebase:firebase-core:11.8.0
cordova.system.library.4=com.google.firebase:firebase-messaging:11.8.0
cordova.gradle.include.1=cordova-plugin-fcm/bar-FCMPlugin.gradle
cordova.gradle.include.2=phonegap-plugin-barcodescanner/bar-barcodescanner.gradle
cordova.gradle.include.3=cordova-android-play-services-gradle-release/bar-cordova-android-play-services-gradle-release.gradle
cordova.system.library.5=com.android.support:appcompat-v7:27.1.0

然后在最下面加上com.android.support:appcompat-v7:27.1.0