Hi, today we will check one of the most common gradle issues with Flag Immutable and Flag Mutable In Flutter.
Problem Statement
You will see the below error statement on your console:-
ava.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of Flag Immutable and 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.
Cause of Problem
This is a Flutter gradle issue that occurs when performing tasks like notifications on devices with API level 31 or above (Android 12 or higher).
If you’re facing this issue in a Flutter app, you need to specify either Flag Immutable or Flag Mutable when creating a PendingIntent in your Android-specific code.
This code is usually located in the Android directory of your Flutter project.
Learn more about our Flutter Development Services.
Solution
Now, the main question is how to resolve this issue.
While solving this issue you need to consider the below point carefully and follow the instructions on it:-
“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.”
Here you will need to change the Flag Mutability and Pending Intent in your project.
You can set your pending intent and Flag Mutability as below:-
1 2 3 4 5 6 |
val updatedPendingIntent = PendingIntent.getActivity( applicationContext, NOTIFICATION_REQUEST_CODE, updatedIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT ) |
Conclusion
In this blog, we have checked one of the most common gradle error popups, with the Flutter applications.
Thanks for reading this blog. You can also check out more amazing blogs on Flutter with Mobikul blogs.