• 14
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

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

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

  • 1
Reply Report
    • @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"? :-)
      • 2
    • Alright ! I finally use @angular/firebase. Now I can get the device token. Next week I will try to send push notifications to firebase !
      • 2
    • 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) ?