4

Recently we released android application targets to 31 which has reported more crashes (only Android OS 12 users) in Firebase Messaging (PendingIntent). When Application is in Pause/Background state on Notification Receive its crashing. I've tried possible solutions but no luck still crashing. As i understood is we have to add PendingIntent.FLAG_IMMUTABLE on PendingIntent start activity but not getting any idea how to add or fix this.

If anyone faced same issue and fixed. Share solution for this.

Thanks in advance...

dependencies{
    implementation platform('com.google.firebase:firebase-bom')
    implementation 'com.google.firebase:firebase-messaging'
    implementation 'com.google.firebase:firebase-iid'
    implementation 'com.google.firebase:firebase-analytics:17.4.4'
    implementation 'com.google.firebase:firebase-crashlytics:17.0.0'
}
E/AndroidRuntime( 7058): java.lang.IllegalArgumentException: com.package: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/AndroidRuntime( 7058): 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.
E/AndroidRuntime( 7058):    at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
E/AndroidRuntime( 7058):    at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
E/AndroidRuntime( 7058):    at android.app.PendingIntent.getActivity(PendingIntent.java:444)
E/AndroidRuntime( 7058):    at android.app.PendingIntent.getActivity(PendingIntent.java:408)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.CommonNotificationBuilder.createContentIntent(com.google.firebase:firebase-messaging@@20.3.0:125)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@20.3.0:27)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@20.3.0:9)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.DisplayNotification.handleNotification(com.google.firebase:firebase-messaging@@20.3.0:27)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@20.3.0:65)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@20.3.0:44)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@20.3.0:27)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@20.3.0:17)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging@@20.3.0:43)
E/AndroidRuntime( 7058):    at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(Unknown Source:6)
E/AndroidRuntime( 7058):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime( 7058):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime( 7058):    at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.6.0:2)
E/AndroidRuntime( 7058):    at java.lang.Thread.run(Thread.java:920)
W/CrashlyticsCore( 7058): Cannot send reports. Settings are unavailable.
D/TransportRuntime.SQLiteEventStore( 7058): Storing event with priority=HIGHEST, name=FIREBASE_CRASHLYTICS_REPORT for destination cct
2
  • paste your show notification code
    – Avital
    Commented Feb 7, 2022 at 7:38
  • @Avital sorry not getting. Show Notification Code mean? Am using Flutter Local Notification when notification receiving onMessage. do you asking that ?
    – Jai Techie
    Commented Feb 7, 2022 at 11:53

3 Answers 3

7

I resolved this finally. Its crashed due to lower version of Firebase Plugins and after upgrading the Android Dependencies and Flutter plugins it got resolved.

Step 1: In android/app/build.gradle

From

implementation 'com.google.firebase:firebase-messaging:20.1.5'

To

implementation platform('com.google.firebase:firebase-bom') // add this 
implementation 'com.google.firebase:firebase-messaging:23.0.0'
implementation 'com.google.firebase:firebase-iid:21.1.0' // add this

Step 2: In Flutter pubspec.yaml

From

firebase_core: ^0.5.0+1
firebase_messaging: ^7.0.3
firebase_remote_config: ^0.4.2
firebase_crashlytics: ^0.1.4+1
firebase_dynamic_links: ^0.6.3
firebase_auth: ^0.18.4+1

To

firebase_core: ^1.10.0
firebase_messaging: ^11.2.6
firebase_remote_config: ^2.0.0
firebase_crashlytics: ^2.5.0
firebase_dynamic_links: ^4.0.5
firebase_auth: ^3.3.6
2
  • 1
    Thanks a lot. I am also faced this issue this answer helps me to fix... Commented Mar 15, 2022 at 5:58
  • I'm using an old version of flutter and dart 2.12 didn't upgraded my app yet, so is there another way to fix this issue ? thx
    – karmous
    Commented Dec 1, 2022 at 11:58
3

As per the official doc "If your app targets Android 12, you must specify the mutability of each PendingIntent object that your app creates. This additional requirement improves your app's security."

Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

   
PendingIntent contentIntent = PendingIntent.getActivity(context,NOTIFICATION_REQUEST_CODE, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);

we’re constructing a standard type of Intent that will open our app, and then simply wrapping that in a PendingIntent before adding it to our notification.In this case, since we have an exact action we know we want to perform, we construct a PendingIntent that cannot be modified by the app we pass it to by utilizing a flag called FLAG_IMMUTABLE.

2
  • 1
    thanks for replying. Yes you are correct as per the official doc if application using target level 31 we have to add FLAG_IMMUTABLE. But my question is am using Flutter Firebase Messaging Plugin and from firebase-messaging onMessage receive app is getting crashed like above mentioned. How to add that FLAG_IMMUTABLE and solve in com.google.firebase:firebase-messaging?
    – Jai Techie
    Commented Feb 7, 2022 at 11:59
  • share your code of firebase-messaging onMessage method. Commented Feb 7, 2022 at 14:26
0

update com.google.firebase:firebase-messaging:

From

implementation 'com.google.firebase:firebase-messaging:20.1.5'

To

implementation 'com.google.firebase:firebase-messaging:23.0.0'  
implementation 'com.google.firebase:firebase-iid:21.1.0' 

and sync project with Gradle Files

Not the answer you're looking for? Browse other questions tagged or ask your own question.