问题
定位到S+(版本31及以上)需要在创建PendingIntent时指定FLAG_IMMUTABLE或FLAG_MUTABLE中的一个。我在将目标SDK更新为31后遇到了这个问题。错误始终出现在AlarmPingSender之后。但我不知道任何使用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)
我已完成的工作
- 将WorkManager升级到2.7.0版本
- 将AllProject设置为强制使用WorkManager 2.7.0
- 更改所有现有PendingIntent以使用FLAG_IMMUTABLE标志
- 有些旧代码仍在使用gcm,需要禁用它
- 更新所有Firebase包(一些人说这是由于分析后续版本的原因)
使用的库
- OneSignal
- Qiscus
- Firebase
- WorkManager
org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:76)
引起的,这似乎与你正在使用的MQTT库有关。 - ianhanniballake