App crashes : Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent

Issue

After updating targetsdk version to 31, the app is giving an error on pending intents. I have updated all the pending intents and then run the app. But the app is now crashing with this error

Caused by: java.lang.IllegalArgumentException: fm.iono.p953: 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.

But the line that the app crashes is the following:

val gmsTracker = GoogleAnalytics.getInstance(context).newTracker(gmsId)

see the screenshot below. I have highlighted the line with blue color where the app crashes. And from the logcat you can see the error. Not sure why the app is crashing on the line where no pending intent is available 🙂

enter image description here

Any help will be appreciated

Solution

Make sure you are on the latest version of the Google Analytics dependency. It apparently is setting up that PendingIntent, and only the developers of Google Analytics can change that behavior.

Answered By – CommonsWare

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published