how to resolve Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent

I am having an issue with firebase messaging service, when ever I receive a notification I get this error

java.lang.IllegalArgumentException: io.ohme.android.dev: 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.

in the fcmService I am already using FLAG_IMMUTABLE for pending intents. Not so sure where to make make changes.

gradle for reference

implementation("com.google.android.gms:play-services-vision:20.1.3")
implementation("com.google.firebase:firebase-bom:26.8.0")
implementation("com.google.firebase:firebase-auth-ktx")
implementation("com.firebaseui:firebase-ui-auth:7.2.0")
implementation ("androidx.work:work-runtime-ktx:2.8.1") // Added this as per some of the answers

    minSdk = 26
    targetSdk = 34
compileSdk = 34

this is the full error, please suggest what I can do to resolve this.

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:382)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465)
at android.app.PendingIntent.getActivity(PendingIntent.java:451)
at android.app.PendingIntent.getActivity(PendingIntent.java:415)
at com.google.firebase.messaging.CommonNotificationBuilder.createContentIntent(com.google.firebase:firebase-messaging@@21.0.1:5)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@21.0.1:20)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@21.0.1:6)
at com.google.firebase.messaging.DisplayNotification.handleNotification(com.google.firebase:firebase-messaging@@21.0.1:4)
at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@21.0.1:8)
at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@21.0.1:8)
at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@21.0.1:3)
at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@21.0.1:3)
at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(Unknown Source:1)
at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(Unknown Source:6)
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(com.google.android.gms:play-services-basement@@18.0.0:2)
at java.lang.Thread.run(Thread.java:920)

Thanks in advance
R

  • Have you tried updating from 21.0.1 to 23.2.1

    – 

  • Hello @EpicPandaForce thank you for responding, this is what I have in gradle for firebase messaging – ` implementation(“com.google.firebase:firebase-messaging”)`

    – 




  • 2

    Sounds like you should update the BOM.

    – 

  • ok that makes sense, implementation(“com.google.firebase:firebase-bom:26.8.0”) this is what I have currently, will update to 32.3.1

    – 

Leave a Comment