pusher / push-notifications-android

Android SDK for Pusher Beams
https://www.pusher.com/beams
MIT License
21 stars 21 forks source link

100% Crash in Android 12 - missing PendingIntent Flags #127

Closed akaita closed 2 years ago

akaita commented 2 years ago

We have a 100% crash rate in Android 12.

Error stack:

2021-11-02 15:41:37.466 10394-10435/com.4rtstudio.android.debug E/AndroidRuntime: FATAL EXCEPTION: pool-16-thread-1
    Process: com.akaita.android.debug, PID: 10394
    java.lang.IllegalArgumentException: com.4rtstudio.android.debug: 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 androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:273)
        at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:151)
        at androidx.work.impl.utils.ForceStopRunnable.forceStopRunnable(ForceStopRunnable.java:171)
        at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:102)
        at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)

This only happens when the implementation 'com.pusher:push-notifications-android:1.7.0' dependency is present

akaita commented 2 years ago

As a workaround, you can force Pusher to use a newer version of WorkManager:

    implementation 'com.pusher:push-notifications-android:1.7.0'
    constraints {
        implementation('androidx.work:work-runtime-ktx:2.7.0') {
            because 'Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. https://github.com/pusher/push-notifications-android/issues/127'
        }
    }
benw-pusher commented 2 years ago

Thanks for getting in touch. We just need to build a new release to resolve this, this issue was resolved in #124 which is merged but not released. I'll let you know when we push the new version.

akaita commented 2 years ago

@benw-pusher that's not the same bug. Actually, you will probably notice that I myself created that PR as well :) That was a compilation-time issue. This is a runtime issue.