Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Android 12 background notification led to crash (PendingIntent) #1876

Open
dnepromell opened this issue Mar 25, 2022 · 6 comments
Open

Android 12 background notification led to crash (PendingIntent) #1876

dnepromell opened this issue Mar 25, 2022 · 6 comments

Comments

@dnepromell
Copy link

"@nativescript/firebase": "^11.1.3"

compileSdkVersion 31
targetSdkVersion 31

Crash stacktrace:

An uncaught Exception occurred on "Firebase-MyFirebaseMessagingService" thread.
com.uboro.mobile: 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.

StackTrace:
java.lang.IllegalArgumentException: com.uboro.mobile: 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:375)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
at android.app.PendingIntent.getActivity(PendingIntent.java:444)
at android.app.PendingIntent.getActivity(PendingIntent.java:408)
at com.google.firebase.messaging.zzb.zza(com.google.firebase:firebase-messaging@@20.1.0:59)
at com.google.firebase.messaging.zzd.zza(com.google.firebase:firebase-messaging@@20.1.0:33)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(com.google.firebase:firebase-messaging@@20.1.0:69)
at com.google.firebase.messaging.zze.run(com.google.firebase:firebase-messaging@@20.1.0:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:6)
at java.lang.Thread.run(Thread.java:920)

The bug in the firebase was fixed in firebase/firebase-android-sdk#3115
But the current version of nativescript plugin uses the old version of firebase sdk

implementation "com.google.firebase:firebase-messaging:20.1.0"

@hsluis
Copy link

hsluis commented Apr 3, 2022

Any updates on this? I am also experience a lot of crashes.

@Ederagp
Copy link

Ederagp commented Apr 6, 2022

@dnepromell @hsluis Hello,
Following the firebase documentation indicates this:
Caution: This is a breaking change for apps that use FCM and the deprecated Firebase Instance ID API to manage registration tokens. We strongly recommend [migrating to FCM's token APIs](https://firebase.google.com/docs/projects/manage-installations#fid-iid). If you're unable to migrate to the replacement APIs, add a direct dependency on the firebase-iid library to your build.gradle file.

adding this fixes the error:
implementation "com.google.firebase:firebase-iid:21.1.0"

@dnepromell
Copy link
Author

@Ederagp thanks for your help.
Adding this library fixes the crash issue.
But I noticed after it there are no push notifications.

So I also changed "com.google.firebase:firebase-messaging:20.1.0" to "com.google.firebase:firebase-messaging:21.1.0"

And now all works perfectly on Android 12 and the versions below.

@tommag21
Copy link

tommag21 commented Jul 8, 2022

Thanks @dnepromell.

I added these lines to my app.gradle file and now my push notifications work:

dependencies {
  implementation "com.google.firebase:firebase-iid:21.1.0"
  implementation "com.google.firebase:firebase-messaging:22.0.0"
  // ...
}

android {
  compileSdkVersion 31
  defaultConfig {
    targetSdkVersion 31
    // ...
  }
  // ...
}

I changed the version of firebase-messaging to 22.0.0 because v. 21.1.0 had a bug where tapping a notification would not launch the app.

@yashpyraj
Copy link

Thanks @dnepromell.

I added these lines to my app.gradle file and now my push notifications work:

dependencies {
  implementation "com.google.firebase:firebase-iid:21.1.0"
  implementation "com.google.firebase:firebase-messaging:22.0.0"
  // ...
}

android {
  compileSdkVersion 31
  defaultConfig {
    targetSdkVersion 31
    // ...
  }
  // ...
}

I changed the version of firebase-messaging to 22.0.0 because v. 21.1.0 had a bug where tapping a notification would not launch the app.

after this change android 12 is working fine but old version not getting notification !!!

@nikoTM
Copy link

nikoTM commented Feb 9, 2023

@yashpyraj which Android versions are you getting issues on? This seems to be working on Android 10,11,12 for me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants