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

时间:2018-01-07 14:46:29

标签: android cordova ionic-framework cordova-plugin-fcm

由于我在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.gradle project.properties 中将所有Verison更改为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;

如果您需要更多的东西,请告诉我,我会添加它!

2 个答案:

答案 0 :(得分:2)

您可以使用my answer

只需编辑:

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

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

classpath' 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" />

答案 1 :(得分:0)

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

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