3

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 (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

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
Emilien
  • 2,701
  • 4
  • 15
  • 25
  • 1
    Same issue here. And other issues when trying other push plugins. There does not seem to be any way to make this work without some hack to a file and even then there are other issues that follow. I have been at this for days on this particular push issue. And weeks with issues related to Ionic 4 and things that used to work before. – Various Artist Apr 04 '19 at 18:45
  • @VariousArtist So you haven’t found a solution for Ionic 4 ? I tried others push plugins too, but it didn’t work .. – Emilien Apr 04 '19 at 19:33
  • 1
    No I am still having problems. I think we need to do some hack in the project.properties file under the android platform folder, but I am not sure exactly what to change there. Everything I have read on this seems to be slightly different but nothing has worked for me yet – Various Artist Apr 04 '19 at 22:07
  • 1
    This is one link I am reading about now https://stackoverflow.com/questions/45500934/error-fix-the-version-conflict-google-services-plugin – Various Artist Apr 04 '19 at 22:07
  • 1
    I am also reading this to try to figure it out https://developers.google.com/android/guides/versioning#strict_version_matching – Various Artist Apr 04 '19 at 22:09
  • 1
    This looked the most promising! Alas it didn't work for me, but I think the fix is in here somewhere https://github.com/dpa99c/cordova-android-play-services-gradle-release – Various Artist Apr 04 '19 at 23:18

2 Answers2

1

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

Various Artist
  • 357
  • 5
  • 16
  • I installed it ! And it build successfully ! So thanks for it ! But, have you tired it with FCM plugin (`ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated`) ? – Emilien Apr 05 '19 at 07:52
  • @Emilien I seem to be making good progress with the cordova-plugin-firebase, so I haven't yet tried with the other one you mentioned yet (although it was one of many I had tried before and I do plan on giving it another go now that I can build). Glad I could help -- Can you mark my solution as the "Correct Answer"? :-) – Various Artist Apr 05 '19 at 16:54
  • 1
    Alright ! I finally use @angular/firebase. Now I can get the device token. Next week I will try to send push notifications to firebase ! – Emilien Apr 05 '19 at 17:32
0

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.

Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167