paho.mqtt.android
paho.mqtt.android copied to clipboard
App crashing due to PendingIntent flag FLAG_IMMUTABLE on targetting API 31 SDK
Please fill out the form below before submitting, thank you!
- [ ] Bug exists Release Version 1.1.1 (Java Repository Master Branch)
- [ ] Bug exists in Snapshot Version 1.1.2-SNAPSHOT (Android Service Repository Master Branch)
- [ ] Bug is just in the Sample Application.
__Android API Version Bug Seen on: API 31
__Android Version Bug Seen on: Android 12
Please also check that if you have found the bug in the Release version (1.1.1) that you check that it also exists in the Snapshot (1.1.2-SNAPSHOT) before raising a bug.
Description of Bug:
Just initialize mqtt connection on a Android API 31 version device and you will get this exception. I have done this on Pixel 4A API S device. I'm using the following dependency - implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5' implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
Console Log output (if available):
java.lang.IllegalArgumentException: Targeting S+ (version 10000 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:1214) at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:1050) at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:151)
I have the same situation as you
Same here. Should be a very simple fix, but looking at the commit history, I am wondering if there will be any or if it is time to migrate to something else...
I have the same situation as you
Did you tried this more modern repo https://github.com/hannesa2/paho.mqtt.android ? You can give it a try
@hannesa2 Are you sure your library won't reproduce the same error? I see that you also do not pass the FLAG_IMMUTABLE flag when creating a PendingIntent in AlarmPingSender line 53...
@rushsports As far as I understand I run app with 31 https://github.com/hannesa2/paho.mqtt.android/blob/master/extendedSample/build.gradle#L13 , library comes with 31 https://github.com/hannesa2/paho.mqtt.android/blob/master/serviceLibrary/build.gradle#L13 and Espresso tests are on a device api30 and api28 and I don't observe an error.
When you found an error, I would merge the pull request. But first I want to see the error on my tests
@hannesa2 it is reproducible. From android 12 it is mandatory to set FLAG_IMMUTABLE or FLAG_MUTABLE for a PendingIntent. In kotlin we did like this: https://github.com/Infomaniak/android-kDrive/blob/master/app/src/main/java/com/infomaniak/drive/data/sync/UploadNotifications.kt#L40
@JorisBodin Please show me a failing test. I don't see it
@hannesa2 You can compile and launch our application on Android 12, as soon as it connects to MQTT the application crashes ...
Probably your app will crash, but why mine not. Where is the diff ?
on Android 12 device?
Anyway, switch to my repo (it's not this one !), make a pull request there and we will solve it.
on Android 12 device?
Ahh, there is the diff https://github.com/hannesa2/paho.mqtt.android/blob/master/.github/workflows/Android-CI-Espresso.yml#L16 it's Android 11 (API level 30)
Here you have the fix for Android 12 (api 31)
Is there anyone solved?
Use the fork of @hannesa2, the problem is fixed
I was facing this issue with room database on the @hannesa2 fork. If someone else is facing this, you can use my fork. I made changes over the latest release (v1.1.1) on the eclipse repo to make it work. You can use v1.1.3 release on my repo (also available on jitpack).
I have the same problem
Same here!
I followed your solution as below :
1- Imported serviceLibrary_release.aar (added in libs directory) 2- I also added in build.gradle (in root) allprojects { repositories { ... flatDir { dirs 'libs' } }
in build.gradle : implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5' implementation (name:'serviceLibrary_release', ext:'aar')
Voila , Build output : Execution failed for task ':...'. > 1 exception was raised by workers: java.lang.RuntimeException: Duplicate class info.mqtt.android.service.Ack found in modules jetified-serviceLibrary_release-runtime.jar @hannesa2
@mohammadfazelp I don't know what I should do here in this dead repo. Maybe you give my fork a try ?
@mohammadfazelp @movaffagh @mukul29 The database issue is solved https://github.com/hannesa2/paho.mqtt.android/issues/249#issuecomment-1014245327
My app was forced to upgrade to Target 31. I encountered this problem and couldn't wait for the new version. I just forked and repackaged the version myself. implementation 'cn.bingerz.android:org.eclipse.paho.android.service:1.1.2-SNAPSHOT'
Update content: Support AndroidX. Upgrade Gradle to 7.x. Fix PendingIntent flag FLAG_IMMUTABLE issue. Avoid Permission Denial: getIntentForIntentSender() issue.
For specific modifications, please see: https://github.com/bingerz/flip-mqtt-android
@hannesa2 I am facing an issue with your fork also.
https://github.com/hannesa2/paho.mqtt.android/issues/307
Will there be an official release from org.eclipse.paho.android with a fix for this android-12 issue?
I have the same situation as you
same here
same here
how can we try to get this officially merged?