Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashing due to PendingIntent flag FLAG_IMMUTABLE on targetting API 31 SDK #465

Open
3 tasks
harpreet830 opened this issue Aug 24, 2021 · 31 comments
Open
3 tasks

Comments

@harpreet830
Copy link

harpreet830 commented Aug 24, 2021

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)

@lightningrealm
Copy link

I have the same situation as you

@Staacks
Copy link

Staacks commented Aug 30, 2021

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...

@lindabang
Copy link

I have the same situation as you

@hannesa2
Copy link
Contributor

Did you tried this more modern repo https://github.com/hannesa2/paho.mqtt.android ?
You can give it a try

@rushsports
Copy link

@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...

@hannesa2
Copy link
Contributor

hannesa2 commented Sep 22, 2021

@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

@JorisBodin
Copy link

@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

@hannesa2
Copy link
Contributor

hannesa2 commented Oct 5, 2021

@JorisBodin Please show me a failing test. I don't see it

@JorisBodin
Copy link

@hannesa2 You can compile and launch our application on Android 12, as soon as it connects to MQTT the application crashes ...

@hannesa2
Copy link
Contributor

hannesa2 commented Oct 5, 2021

Probably your app will crash, but why mine not. Where is the diff ?

@lightningrealm
Copy link

on Android 12 device?

@hannesa2
Copy link
Contributor

hannesa2 commented Oct 5, 2021

Anyway, switch to my repo (it's not this one !), make a pull request there and we will solve it.

@hannesa2
Copy link
Contributor

hannesa2 commented Oct 5, 2021

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)

@hannesa2
Copy link
Contributor

hannesa2 commented Oct 5, 2021

Here you have the fix for Android 12 (api 31)

@lightningrealm
Copy link

Is there anyone solved?

@JorisBodin
Copy link

Use the fork of @hannesa2, the problem is fixed

@mukul29
Copy link

mukul29 commented Dec 8, 2021

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).

@movaffagh
Copy link

I have the same problem

@mohammadfazelp
Copy link

Same here!

@mohammadfazelp
Copy link

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

@hannesa2
Copy link
Contributor

@mohammadfazelp I don't know what I should do here in this dead repo. Maybe you give my fork a try ?

@hannesa2
Copy link
Contributor

@mohammadfazelp @movaffagh @mukul29
The database issue is solved
hannesa2/paho.mqtt.android#249 (comment)

@YangShaoXiong
Copy link

Here you have the fix for Android 12 (api 31)

thank you

@bingerz
Copy link

bingerz commented Apr 27, 2022

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

@Slake07
Copy link

Slake07 commented May 11, 2022

@hannesa2 I am facing an issue with your fork also.

hannesa2/paho.mqtt.android#307

@gopaladhith
Copy link

Will there be an official release from org.eclipse.paho.android with a fix for this android-12 issue?

@FordGT40
Copy link

FordGT40 commented Jun 6, 2022

I have the same situation as you

@pricimus
Copy link

same here

1 similar comment
@pricimus
Copy link

same here

@anujtripathi04
Copy link

how can we try to get this officially merged?

@Javatraher
Copy link

Javatraher commented Jun 28, 2022

@hannesa2 Hello, I installed your library, a new error started popping up, here it is:"Exception 'org.eclipse.paho.client.mqttv3.MqttException' is never thrown in the corresponding try block".Tell me what to do with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests