无法应用插件 [class 'com.google.gms.googleservices.GoogleServicesPlugin'](对于输入字符串:“+”)

Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin'] (For input string: "+")

我想使用 Firebase Cloud Messenging 服务实现推送通知。我补充说:

ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated
npm install @ionic-native/fcm

app.component.ts中:

import { FCM } from '@ionic-native/fcm/ngx';

// ...

constructor(private fcm: FCM)

// ...

this.fcm.getToken().then(token => {
    console.log('Token :', token);
});

这让我在桌面上出错,因为 Cordova 不可用,没关系。

但是当我想在 android 上测试时,像往常一样,我会: ionic cordova run android --device

这给我一个错误:

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\<username>\Documents\weezchat_ionic\platforms\android\cordova-plugin-fcm-with-dependecy-updated\billingtests-FCMPlugin.gradle' line: 21

* What went wrong:
A problem occurred evaluating script.
> Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
   > For input string: "+"

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
[ERROR] An error occurred while running subprocess cordova.

        cordova run android --device exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

我正在与 :

一起工作
Ionic:

   ionic (Ionic CLI)             : 4.12.0 (C:\Users\username\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.1.1
   @angular-devkit/build-angular : 0.13.6
   @angular-devkit/schematics    : 7.2.4
   @angular/cli                  : 7.3.6
   @ionic/angular-toolkit        : 1.4.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.4, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 8 other plugins)

System:

   Android SDK Tools : 26.1.1 (C:\Users\username\AppData\Local\Android\Sdk)
   NodeJS            : v10.15.3 (C:\Program Files\nodejs\node.exe)
   npm               : 6.9.0
   OS                : Windows 10

这是\platforms\android\cordova-plugin-fcm-with-dependency-updated\billingtests-FCMPlugin.gradle内容:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.+'
        classpath 'com.google.gms:google-services:3.1.+'
    }
}
repositories {
    mavenCentral()
    jcenter()
}
dependencies {
    compile 'com.google.firebase:firebase-core:10.+'
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin

我遇到了完全相同的问题,并最终能够使用此 link 中的信息进行一些猜测来解决它: cordova-android-play-services-gradle-release

这涉及到添加一个特殊的插件来尝试设置所需的播放服务版本号。这个特定设置对我有用:

cordova plugin add cordova-android-play-services-gradle-release --variable PLAY_SERVICES_VERSION=16+

基本上这似乎只是将版本号自动添加到 config.xml:

<plugin name="cordova-android-play-services-gradle-release" spec="^2.1.0">
    <variable name="PLAY_SERVICES_VERSION" value="16+" />
</plugin>

也许您的情况需要不同的版本号,或者因为您使用的是 Ionic 4 并尝试添加推送插件,所以版本号可能相同。无论哪种方式,我相信答案就在这个设置中的某个地方。

*注意:这是与插件 cordova-plugin-firebase

一起使用的

我遇到了同样的问题,那是因为我错过了 com.google.gms:google-services 依赖项。我这样做是因为我在 Flutter 中重新生成了 Android 个文件:

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath 'com.google.gms:google-services:4.3.8'
    }

确保按照 set up documentation 中的说明进行操作。