Emilien
Emilien

Reputation: 2761

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

I want to implement push notifications with Firebase Cloud Messenging service. I added :

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

In app.component.ts :

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

// ...

constructor(private fcm: FCM)

// ...

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

This make me an error in desktop, because Cordova is not available, it's ok.

But when I want to test on android, as usual, I make : ionic cordova run android --device

And this give me an error :

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.

I'm working with :

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 ([email protected])
   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

This is \platforms\android\cordova-plugin-fcm-with-dependency-updated\billingtests-FCMPlugin.gradle content :

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

Upvotes: 3

Views: 954

Answers (2)

Ben Butterworth
Ben Butterworth

Reputation: 28572

I had the same issue, and it was because I missed the com.google.gms:google-services dependency. I did it because I regenerated the Android files in Flutter:

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

Make sure you follow the instructions in the set up documentation.

Upvotes: 0

Various Artist
Various Artist

Reputation: 417

I had exactly the same issue and was finally able to solve it using a bit of guesswork with the information in this link: cordova-android-play-services-gradle-release

This involves adding a special plugin to try and set the desired play services version number. This particular setting worked for me:

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

Basically this seems to be simply adding a version number automatically into the config.xml:

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

Perhaps your situation you need a different version number, or maybe it'll be the same since you are using Ionic 4 and trying to add the push plugin. Either way, I believe the answer is in this setting somewhere.

*NOTE: this is in conjunction with the plugin cordova-plugin-firebase

Upvotes: 1

Related Questions