andrehtissot / cordova-plugin-fcm-with-dependecy-updated

Google FCM Push Notifications Cordova Plugin
MIT License
210 stars 273 forks source link

changing targetSdkVersion to 31 make notification not fired #299

Open kotran88 opened 1 year ago

kotran88 commented 1 year ago

on config.xml

<preference name="android-targetSdkVersion" value="31" />

I used it with value 30 and notificiation work find! but changing it to 31, then rm android and add androoid@10, then it is not fired.

on package.json


    "cordova-plugin-fcm-with-dependecy-updated": "^4.2.0",

"cordova-plugin-fcm-with-dependecy-updated": {
        "FCM_VERSION": "19.0.0",
        "GRADLE_TOOLS_VERSION": "3.5.3",
        "GOOGLE_SERVICES_VERSION": "4.3.3",
        "SUPPORT_LIBRARY_VERSION": "28.0.0",
        "ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/ic_launcher"
      }

ionic info


Ionic:

   Ionic CLI          : 5.4.16 (/Users/pedrojung/.nvm/versions/node/v14.17.3/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.1

Cordova:

   Cordova CLI       : 11.0.0
   Cordova Platforms : android 10.1.2
   Cordova Plugins   : cordova-plugin-ionic-webview 4.0.1, (and 30 other plugins)

Utility:

   cordova-res                          : 0.15.4
   native-run (update available: 1.7.1) : 1.5.0

System:

   Android SDK Tools : 26.1.1 (/Users/pedrojung/Library/Android/sdk/)
   ios-deploy        : 1.11.4
   NodeJS            : v14.17.3 (/Users/pedrojung/.nvm/versions/node/v14.17.3/bin/node)
   npm               : 6.14.13
   OS                : macOS Ventura
   Xcode             : Xcode 14.2 Build version 14C18
dimitriscsd commented 1 year ago

I am having a similar issue. Notifications only show up in the foreground.

As a matter of fact, for me (running android 13 on samsung S21 FE 5G), if the app is in the background and a push arrives, the app crashes!

Hopefully somebody can help with this...

thepsion5 commented 1 year ago

I've been running into the same issue, and I've identified the cause. Testing the receipt of push notifications using an emulator running the app, I see this fatal error:

FATAL EXCEPTION: Firebase-Messaging-Intent-Handle
Process: com.my-workplace.MyAppIdentifier, PID: 8789
java.lang.IllegalArgumentException: com.tnsos.GoVoteTN: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

Doing some further research, this may be caused by specifying an outdated version of the FCM library as part of the preferences when adding the plugin, but so far my attempts to update it have met with other errors. I'll continue to add information as I go.

flyingcat42 commented 1 year ago

@thepsion5 @dimitriscsd @kotran88 This fixed it for me https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/issues/293#issuecomment-1377487961

freescout-helpdesk commented 1 year ago

As a matter of fact, for me (running android 13 on samsung S21 FE 5G), if the app is in the background and a push arrives, the app crashes!

We have exactly the same issue. Notifications work fine on older Android versions but causing the app to crash on Android 12, 13 (https://github.com/freescout-helpdesk/freescout/issues/2718)

freescout-helpdesk commented 1 year ago

@thepsion5 Have you found the solution? This solution https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/issues/293#issuecomment-1377487961 does not work for us - still no push notifications on Android 13.

dimitriscsd commented 1 year ago

The solution definitely works.

After replacing the plugins, have you deleted your platforms and plugins folders and then built again? That needs to happen for the new plugin files to be placed in the platform.

freescout-helpdesk commented 1 year ago

Android platform is removed and re-added. Still push notifications work on Android 9 phone but don't work on Android 13 (notifications are allowed for the app in the phone settings).

cordova plugin remove cordova-plugin-fcm-with-dependecy-updated cordova plugin add https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated#v6.3.1 --variable ANDROID_DEFAULT_NOTIFICATION_ICON="@mipmap/ic_launcher" --variable ANDROID_FCM_VERSION="23.0.0" --variable ANDROID_FIREBASE_BOM_VERSION="29.0.1" --variable ANDROID_GOOGLE_SERVICES_VERSION="4.3.4" --variable ANDROID_GRADLE_TOOLS_VERSION="4.1.0" --variable IOS_FIREBASE_MESSAGING_VERSION="~> 7.4.0" cordova platform remove android cordova platform add android@8.1.0

Excerpt from config.xml:

    <platform name="android" spec="~8.1.0">
        <allow-intent href="market:*" />
        <preference name="android-minSdkVersion" value="19" />
        <preference name="android-targetSdkVersion" value="31" />
    </platform>
    <engine name="android" spec="^8.1.0" />
    <plugin name="cordova-plugin-fcm-with-dependecy-updated" spec="6.3.1">
        <variable name="ANDROID_DEFAULT_NOTIFICATION_ICON" value="@mipmap/ic_launcher" />
        <variable name="ANDROID_FCM_VERSION" value="23.0.0" />
        <variable name="ANDROID_FIREBASE_BOM_VERSION" value="29.0.1" />
        <variable name="ANDROID_GOOGLE_SERVICES_VERSION" value="4.3.4" />
        <variable name="ANDROID_GRADLE_TOOLS_VERSION" value="4.1.0" />
        <variable name="IOS_FIREBASE_MESSAGING_VERSION" value="~&gt; 7.4.0" />
        <variable name="FCM_CORE_VERSION" value="16.0.9" />
        <variable name="FCM_VERSION" value="18.0.0" />
        <variable name="GRADLE_TOOLS_VERSION" value="3.5.0" />
        <variable name="GOOGLE_SERVICES_VERSION" value="4.2.0" />
    </plugin>
dimitriscsd commented 1 year ago

Android platform is removed and re-added. Still push notifications work on Android 9 phone but don't work on Android 13 (notifications are allowed for the app in the phone settings).

cordova plugin remove cordova-plugin-fcm-with-dependecy-updated cordova plugin add https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated#v6.3.1 --variable ANDROID_DEFAULT_NOTIFICATION_ICON="@mipmap/ic_launcher" --variable ANDROID_FCM_VERSION="23.0.0" --variable ANDROID_FIREBASE_BOM_VERSION="29.0.1" --variable ANDROID_GOOGLE_SERVICES_VERSION="4.3.4" --variable ANDROID_GRADLE_TOOLS_VERSION="4.1.0" --variable IOS_FIREBASE_MESSAGING_VERSION="~> 7.4.0" cordova platform remove android cordova platform add android@8.1.0

Excerpt from config.xml:

    <platform name="android" spec="~8.1.0">
        <allow-intent href="market:*" />
        <preference name="android-minSdkVersion" value="19" />
        <preference name="android-targetSdkVersion" value="31" />
    </platform>
    <engine name="android" spec="^8.1.0" />
    <plugin name="cordova-plugin-fcm-with-dependecy-updated" spec="6.3.1">
        <variable name="ANDROID_DEFAULT_NOTIFICATION_ICON" value="@mipmap/ic_launcher" />
        <variable name="ANDROID_FCM_VERSION" value="23.0.0" />
        <variable name="ANDROID_FIREBASE_BOM_VERSION" value="29.0.1" />
        <variable name="ANDROID_GOOGLE_SERVICES_VERSION" value="4.3.4" />
        <variable name="ANDROID_GRADLE_TOOLS_VERSION" value="4.1.0" />
        <variable name="IOS_FIREBASE_MESSAGING_VERSION" value="~&gt; 7.4.0" />
        <variable name="FCM_CORE_VERSION" value="16.0.9" />
        <variable name="FCM_VERSION" value="18.0.0" />
        <variable name="GRADLE_TOOLS_VERSION" value="3.5.0" />
        <variable name="GOOGLE_SERVICES_VERSION" value="4.2.0" />
    </plugin>

The commands above are not correct. You are removing the plugin, then re-adding the same one, instead of the fork.

I am providing again the commands that will install the fork with the fix. Note that after "github.com" on the url, the username is different:

cordova plugin remove cordova-plugin-fcm-with-dependecy-updated

cordova plugin add https://github.com/marutifh/cordova-plugin-fcm-with-dependecy-updated --variable ANDROID_DEFAULT_NOTIFICATION_ICON="@mipmap/ic_launcher" --variable ANDROID_FCM_VERSION="23.0.0" --variable ANDROID_FIREBASE_BOM_VERSION="29.0.1" --variable ANDROID_GOOGLE_SERVICES_VERSION="4.3.4" --variable ANDROID_GRADLE_TOOLS_VERSION="4.1.0" --variable IOS_FIREBASE_MESSAGING_VERSION="~> 7.4.0"
freescout-helpdesk commented 1 year ago

Thanks. Now we are getting the following error when doing cordova build android --prod:

FCMPlugin: Support for Gradle v4 or lower is deprecated. Please upgrade to a newer version.

It comes from here https://github.com/marutifh/cordova-plugin-fcm-with-dependecy-updated/blob/master/src/android/FCMPlugin.gradle#L100 and thrown because in our config.xml we have ANDROID_GRADLE_TOOLS_VERSION 4.1.0:

<variable name="ANDROID_GRADLE_TOOLS_VERSION" value="4.1.0" />
dimitriscsd commented 1 year ago

Not sure about that one. Depends on your setup.

What I do know is, the configuration for this plugin (and most plugins for that matter) should now reside in package.json and not in config.xml

Cordova switched away from putting that stuff in config.xml quite a while ago. I would remove that whole segment you have mentioned a few comments above from config.xml and I'd make sure my package.json looks ok.

For reference, my package.json, in terms of this plugin looks like this:

   "cordova": {
    "plugins": {
      "cordova-plugin-fcm-with-dependecy-updated": {
        "ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/ic_launcher",
        "ANDROID_FCM_VERSION": "23.0.0",
        "ANDROID_FIREBASE_BOM_VERSION": "29.0.1",
        "ANDROID_GOOGLE_SERVICES_VERSION": "4.3.4",
        "ANDROID_GRADLE_TOOLS_VERSION": "4.1.0",
        "IOS_FIREBASE_MESSAGING_VERSION": "~> 7.4.0"
      }
    },
    "platforms": [
      "android",
      "ios"
    ]
   }

That message about gradle might just be a warning. Is the build finishing or is it failing?

freescout-helpdesk commented 1 year ago

Build is failing:

> Configure project :app

FCMPlugin: Support for Gradle v4 or lower is deprecated. Please upgrade to a newer version.

BUILD FAILED in 5s

/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:processDebugGoogleServices'.
   > Cannot create a proxy class for abstract class 'GoogleServicesTask'.

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

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

Can you please share your versions:

Here is what we have:

freescout-helpdesk commented 1 year ago

After updating nodejs, cordova-android and cordova to newer versions the build succeeded and push notifications are working now on Android 13.

alitalaee commented 10 months ago

marutifh

After updating nodejs, cordova-android and cordova to newer versions the build succeeded and push notifications are working now on Android 13.

Hi bro would you explain how did you fix your issue?

I tried this but it does not work