【发布时间】:2021-10-31 03:54:18
【问题描述】:
问题
定位 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
- 工作经理
【问题讨论】:
-
错误消息说你的错误是由于
org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:76),它看起来与你使用的任何MQTT库有关。 -
是的,我也这么认为,但我不知道是哪个库使用了 MQTT,我猜是 Qiscus,但我尝试更新到最新版本,但问题仍然存在。
-
您可以查看 Gradle's build scan 以查看 Eclipse Paho 库中的依赖项
-
我认为此代码github.com/eclipse/paho.mqtt.android/blob/master/…(第 76 行)需要更新以符合新的 Android 限制。 github.com/eclipse/paho.mqtt.android/issues/465
标签: android kotlin android-pendingintent android-workmanager android-12