Search code examples
androidandroid-intentandroid-pendingintentandroidsdk31

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


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.