57

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
Joseph Sanjaya
  • 741
  • 1
  • 7
  • 9
  • 2
    The error message says that your error is due to `org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:76)`, which looks related to whatever MQTT library you are using. – ianhanniballake Oct 31 '21 at 04:56
  • yeah, i think so too, but i cant figure out what library that used MQTT, my guess is Qiscus, but i tried to update to latest version, but the problem persist. – Joseph Sanjaya Oct 31 '21 at 07:54
  • You can check out [Gradle's build scan](https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html) to see which dependency pulls in the Eclipse Paho library – Lubos Mudrak Oct 31 '21 at 09:29
  • I believe that this code https://github.com/eclipse/paho.mqtt.android/blob/master/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/AlarmPingSender.java (line 76) needs to be updated to comply with new Android restrictions. https://github.com/eclipse/paho.mqtt.android/issues/465 – Cassio Landim Jan 24 '22 at 15:13
  • Just update your Firebase Messaging library version to the latest version (23 or above) and perform the required changes and you are DONE. It will fix that issue. But yes, do add that FLAG_IMMUTABLE to your PendingIntent flag as well in the application code. – Harpreet Nov 16 '22 at 13:56

8 Answers8

42

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'
}
iDecode
  • 22,623
  • 19
  • 99
  • 186
  • For me I had 2.6.1 and I tried updating to 2.8.1 (latest) and API leve to 33, but it gave the same error. When I changed to 2.7.1 it worked. Thanks – Baskar PC Aug 18 '23 at 17:01
22

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

Al-Amin
  • 1,369
  • 1
  • 9
  • 26
9

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'
  • 1
    Works for me. In my case changed to: implementation("androidx.work:work-runtime-ktx:2.7.1") – Cube Jan 26 '22 at 17:09
4

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.

Aiman Qaid
  • 41
  • 1
1

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

Joseph Sanjaya
  • 741
  • 1
  • 7
  • 9
1

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

Dmitriy Mitiai
  • 1,112
  • 12
  • 15
0

required to avoid crash on Android 12 API 31

 implementation 'androidx.work:work-runtime-ktx:2.7.1'
Kamran Khan
  • 408
  • 2
  • 10
  • 1
    The provided answer implementation 'androidx.work:work-runtime-ktx:2.7.1' is for Kotlin only. If using Java, you should use implementation 'androidx.work:work-runtime:2.7.1' instead. Make sure you place this line in the build.gradle(:app) file. The full entry should be as follows: dependencies { implementation 'androidx.work:work-runtime:2.7.1' } (for java) or dependencies { implementation 'androidx.work:work-runtime-ktx:2.7.1'} (for Kotlin) – ONE Jan 16 '23 at 02:35
0

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'
Abolfazl Abbasi
  • 309
  • 2
  • 12