FAQ & Troubleshooting (Android)

The runtime crash using Android Gradle Plugin 7.2.0

The apps using this AGP version will face this error at runtime:

2022-06-14 11:30:19.954 21270-21290/tv.fw.example.discovery E/AndroidRuntime: FATAL EXCEPTION: pool-3-thread-1
    Process: tv.fw.example.discovery, PID: 21270
    java.lang.IllegalArgumentException: tv.fw.example.discovery: 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:174)
        at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:108)
        at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:86)
        at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75)
        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)

Currently based on this StackOverflow thread the best solution is adding the latest work manager dependency to your app:

    // Required to avoid crash on Android 12 API 31
    // https://stackoverflow.com/a/69152986/2359762
    implementation("androidx.work:work-runtime-ktx:2.7.1")

Update to the latest version and the problem will be solved

Last updated