My react native app is crashing on start for android 12 (for some user). I have received error report on crashlytics dashboard. I can't also reproduce the error since app running on my android device just fine. This is the error in crashlytics dashbord. looks like problem with a third party library react-native-firebase but not sure how to fix this, anyone here facing the same problem ?
error:
Fatal Exception: java.lang.IllegalArgumentException: com.halkhata: 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.
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(CommonNotificationBuilder.java:26)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(CommonNotificationBuilder.java:69)
at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(CommonNotificationBuilder.java:34)
at com.google.firebase.messaging.DisplayNotification.handleNotification(DisplayNotification.java:28)
at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(FirebaseMessagingService.java:36)
at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(FirebaseMessagingService.java:130)
at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(FirebaseMessagingService.java:12)
at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(FirebaseMessagingService.java:89)
at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(EnhancedIntentService.java:1)
at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(EnhancedIntentService.java:6)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at com.google.android.gms.common.util.concurrent.zza.run(zza.java:6)
at java.lang.Thread.run(Thread.java:1012)
I had to update the sdk version from 30 to 31. I am getting error in Android 11, this is working fine in android 10. Please suggest me what is wrong.
E/AndroidRuntime: FATAL EXCEPTION: WorkManager-WorkManagerTaskExecutor-thread-0
Process: com.cpplusworld.ams, PID: 25796
java.lang.IllegalArgumentException: com.cpplusworld.ams: 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.
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 :)
Any help will be appreciated
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.
Problem
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. I got it after updating target SDK to 31. the error always come after AlarmPingSender. But i dont know any class that used AlarmPingSender.
2021-10-31 10:43:04.990 17031-17341/com.app.mobile D/AlarmPingSender: Register alarmreceiver to MqttServiceMqttService.pingSender.com.app.mobile-2e24ccbde048f2e91635651784
2021-10-31 10:43:04.993 17031-17341/com.app.mobile E/AndroidRuntime: FATAL EXCEPTION: MQTT Rec: com.app.mobile-2e24ccbde048f2e91635651784
Process: com.app.mobile, PID: 17031
java.lang.IllegalArgumentException: com.app.mobile: 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.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:76)
at org.eclipse.paho.client.mqttv3.internal.ClientState.connected(ClientState.java:1150)
at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:987)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:118)
at java.lang.Thread.run(Thread.java:920)
What I Already done
Upgrade WorkManager to 2.7.0
set AllProject to force use WorkManager to 2.7.0
change all existing PendingIntent to use FLAG_IMMUTABLE
there's old code that still use gcm and disable it
Updating all Firebase package (some said its because of later version of analytics)
Library Used
OneSignal
Qiscus
Firebase
WorkManager
Add the following to your build.gradle(app) dependencies.
dependencies {
// For Java
implementation 'androidx.work:work-runtime:2.7.1'
// For Kotlin
implementation 'androidx.work:work-runtime-ktx:2.7.1'
}
Possible solution
Upgrade google analytics to firebase analaytics. Hope it'll solve your problems.Also upgrade all the library what're you using.
For me below solutions solve the problem.
Add PendingIntent.FLAG_IMMUTABLE to your pending intents.
Here is an example -
PendingIntent pendingIntent = PendingIntent.getActivity(this, alarmID, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
For further information follow this link -
https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE
I had this crash but no 3rd party libraries. Adding this import with the latest version will fix the crash.
implementation 'androidx.work:work-runtime-ktx:2.7.0-beta01'
in addition to others' answers I changed :
implementation 'com.google.firebase:firebase-messaging:20.0.0'
to :
implementation 'com.google.firebase:firebase-messaging:23.0.0'
and its working now.
After several attempt to fix this, i gave up and try to contact Qiscus. And they release new version that handle this Pending Intent behaviour change. So if anyone use Qiscus and got this error, you can use latest tag
https://github.com/qiscus/qiscus-sdk-android/releases/tag/1.3.35
If you use the WorkManager in your project, update it to the latest. If you don't, update all you firebase libraries and google libraries to the latest. I faced with the same problem and I was updating libraries one by one. And I found that updating com.google.android.gms:play-services-ads to the latest solved the problem
required to avoid crash on Android 12 API 31
implementation 'androidx.work:work-runtime-ktx:2.7.1'
It may be one of them according to the answers of others. Or by removing this library:
implementation 'androidx.hilt:hilt-work:1.0.0'
In our app we have dependency: com.huawei.hms:base:6.1.0.302 and use HuaweiApiAvailability class.
As result of calling this function PendingIntent getErrPendingIntent(Context var1, ConnectionResult var2) we have exception:
Process: com...preview, PID: 10355
java.lang.IllegalArgumentException: com...preview: 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.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
at android.app.PendingIntent.getActivity(PendingIntent.java:444)
at android.app.PendingIntent.getActivity(PendingIntent.java:408)
at com.huawei.hms.api.b.getErrPendingIntent(HuaweiApiAvailabilityImpl.java:10)
at com.huawei.hms.common.internal.BaseHmsClient.resolution(BaseHmsClient.java:3)
at com.huawei.hms.common.internal.BaseHmsClient.checkAvailabilityAndConnect(BaseHmsClient.java:34)
at com.huawei.hms.common.internal.BaseHmsClient.connect(BaseHmsClient.java:1)
at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.connect(HuaweiApiManager.java:21)
at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.sendRequest(HuaweiApiManager.java:24)
at com.huawei.hms.common.internal.HuaweiApiManager.connectAndSendRequest(HuaweiApiManager.java:8)
at com.huawei.hms.common.internal.HuaweiApiManager.handleMessage(HuaweiApiManager.java:7)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
Question: are you planning to update PendingIntens with new flag for Android 12?
Update
A new version of the base SDK has been released :
implementation 'com.huawei.hms:base:6.2.0.300'
This issue has been fixed, you can explicitly depend on this version of base sdk first, which should fix the problem.
Thank you for your feedback, the R&D team confirms that a fixed version will be released at the end of September.
Please use the latest version for testing by that time. Thanks.