Receiving Background Firebase Push Notification error

I integrated firebase push notifications in my ionic 6 app. I receive notifications successfully on all devidece but only on one I can’t receive them in background mode. The same device receive the notifications in foreground mode successfully.

I debugged using Android LogCats and the log show this error:

2023-06-14 09:36:08.079 30115-30164 AndroidRuntime          pid-30115                            E  FATAL EXCEPTION: Firebase-Messaging-Intent-Handle Process: it.myappname, PID: 30115
java.lang.IllegalArgumentException: it.myappname: 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.
at android.app.PendingIntent.checkFlags(PendingIntent.java:401)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:484)
at android.app.PendingIntent.getActivity(PendingIntent.java:470)
at android.app.PendingIntent.getActivity(PendingIntent.java:434)
at com.google.firebase.messaging.CommonNotificationBuilder.createContentIntent(com.google.firebase:firebase-messaging@@21.0.0:125)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@21.0.0:27)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@21.0.0:9)
at com.google.firebase.messaging.DisplayNotification.handleNotification(com.google.firebase:firebase-messaging@@21.0.0:27)
at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@21.0.0:55)
at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@21.0.0:34)
at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@21.0.0:27)
at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@21.0.0:17)
at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging@@21.0.0:43)
at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(Unknown Source:6)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:6)
at java.lang.Thread.run(Thread.java:1012)

Ionic info:

Ionic:

   Ionic CLI                     : 7.1.1 (C:\tools\nvm\v16.14.0\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 6.7.4
   @angular-devkit/build-angular : 13.3.11
   @angular-devkit/schematics    : 12.2.18
   @angular/cli                  : 13.3.11
   @ionic/angular-toolkit        : 4.0.0

Cordova:

   Cordova CLI       : 11.1.0
   Cordova Platforms : android 11.0.0, browser 6.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 15 other plugins)

Utility:

   cordova-res : not installed globally
   native-run  : not installed globally

System:

   Android SDK Tools : 26.1.1 (C:\Users\l.santaniello\AppData\Local\Android\Sdk)
   NodeJS            : v16.14.0 (C:\Program Files\nodejs\node.exe)
   npm               : 8.3.1
   OS                : Windows 10

Cordova plugins:

cordova-launch-review 4.0.1 "Launch Review"
cordova-plugin-androidx-adapter 1.1.3 "cordova-plugin-androidx-adapter"
cordova-plugin-androidx 3.0.0 "cordova-plugin-androidx"
cordova-plugin-app-version 0.1.12 "AppVersion"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-facebook-connect 3.2.0 "Facebook Connect"
cordova-plugin-fcm-with-dependecy-updated 7.8.0 "Cordova FCM Push Plugin"
cordova-plugin-globalization 1.11.0 "Globalization"
cordova-plugin-google-analytics 1.9.2 "Google Universal Analytics Plugin"
cordova-plugin-googleplus 8.5.2 "Google SignIn"
cordova-plugin-inappbrowser 5.0.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.2.1 "cordova-plugin-ionic-webview"
cordova-plugin-sign-in-with-apple 0.1.2 "cordova-plugin-sign-in-with-apple"
cordova-plugin-splashscreen 5.0.4 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-stripe 1.5.3 "cordova-plugin-stripe"
cordova-plugin-whitelist 1.3.5 "Whitelist"

Can someone help me?

cordova-plugin-fcm-with-dependecy-updated is not maintained anymore and the firebase version it uses is out of date and doesn’t support SDK 31 or newer

You can try changing the ANDROID_FIREBASE_BOM_VERSION variable version from 26.0.0 (default) to 28.0.0 or newer or ANDROID_FCM_VERSION from 21.0.0 to 23.0.0 or newer.

Thanks @julio-ionic for your reply and support.

I don’t understand where I have to change these versions. in which file? Could you please help me?

Thanks in advance

Have you read the link I shared? it has an example of how to install the plugin defining the variables:

cordova plugin add cordova-plugin-fcm-with-dependecy-updated \
  --variable ANDROID_DEFAULT_NOTIFICATION_ICON="@mipmap/ic_launcher" \
  --variable ANDROID_FIREBASE_BOM_VERSION="26.0.0" \
  --variable ANDROID_GOOGLE_SERVICES_VERSION="4.3.4" \
  --variable ANDROID_GRADLE_TOOLS_VERSION="4.1.0" \
  --variable IOS_FIREBASE_MESSAGING_VERSION="~> 7.4.0"

but you can remove all the variables you don’t want to update

Tried but it not works.

So, I’m trying to migrate at cordova-plugin-firebasex plugin. I edited my souce code, I added new plugin, I removed old plugin but when I build for android, I receive this error:

> Configure project :app
strippedNativeLibsDir is deprecated and no longer used. Please remove it from your build configuration.

> Task :CordovaLib:compileReleaseRenderscript
The RenderScript APIs are deprecated. They will be removed in Android Gradle plugin 9.0. See the following link for a guide to migrate from RenderScript: https://developer.android.com/guide/topics/renderscript/migrate

> Task :app:checkReleaseDuplicateClasses FAILED
<======-------> 46% EXECUTING [22s]
> IDLE
> IDLE
> IDLE

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkReleaseDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.google.android.gms.tagmanager.zzbk found in modules jetified-play-services-tagmanager-api-18.0.2-runtime (com.google.android.gms:play-services-tagmanager-api:18.0.2) and jetified-play-services-tagmanager-v4-impl-11.0.1-runtime (com.google.android.gms:play-services-tagmanager-v4-impl:11.0.1)
     Duplicate class com.google.android.gms.tagmanager.zzbl found in modules jetified-play-services-tagmanager-api-18.0.2-runtime (com.google.android.gms:play-services-tagmanager-api:18.0.2) and jetified-play-services-tagmanager-v4-impl-11.0.1-runtime (com.google.android.gms:play-services-tagmanager-v4-impl:11.0.1)
     Duplicate class com.google.android.gms.tagmanager.zzbm found in modules jetified-play-services-tagmanager-api-18.0.2-runtime (com.google.android.gms:play-services-tagmanager-api:18.0.2) and jetified-play-services-tagmanager-v4-impl-11.0.1-runtime (com.google.android.gms:play-services-tagmanager-v4-impl:11.0.1)
     Duplicate class com.google.android.gms.tagmanager.zzbn found in modules jetified-play-services-tagmanager-api-18.0.2-runtime (com.google.android.gms:play-services-tagmanager-api:18.0.2) and jetified-play-services-tagmanager-v4-impl-11.0.1-runtime (com.google.android.gms:play-services-tagmanager-v4-impl:11.0.1)
     Duplicate class com.google.android.gms.tagmanager.zzbo found in modules jetified-play-services-tagmanager-api-18.0.2-runtime (com.google.android.gms:play-services-tagmanager-api:18.0.2) and jetified-play-services-tagmanager-v4-impl-11.0.1-runtime (com.google.android.gms:play-services-tagmanager-v4-impl:11.0.1)
     Duplicate class com.google.android.gms.tagmanager.zzcd found in modules jetified-play-services-tagmanager-api-18.0.2-runtime (com.google.android.gms:play-services-tagmanager-api:18.0.2) and jetified-play-services-tagmanager-v4-impl-11.0.1-runtime (com.google.android.gms:play-services-tagmanager-v4-impl:11.0.1)

     Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 34s

gradle --version

------------------------------------------------------------
Gradle 7.0
------------------------------------------------------------

Build time:   2021-04-09 22:27:31 UTC
Revision:     d5661e3f0e07a8caff705f1badf79fb5df8022c4

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          12.0.2 (Oracle Corporation 12.0.2+10)
OS:           Windows 10 10.0 amd64

:frowning:

migrated to gradle 7.3.3
generated gradle dependencies: Build Scan™ | Gradle Cloud Services

please help me

The build problem is caused by

implementation "com.google.android.gms:play-services-tagmanager:18.0.2"

If I delete this row from build gradle and then build manually the project using

gradle build

it compile successfully

If I run the ionic cordova command

ionic cordova build android --prod -c test --release -- -- --packageType=bundle

It regenerate build.gradle, add the row and build fails.

I don’t know how solve the conflict