Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Main Activity fails to start up due to PendingIntent Flag error

I'm developing a system app, and when I attempt to start it up from the home screen in Android 31, it fails and an java.lang.IllegalArgumentException is thrown. Here's what the stack trace looks like:

java.lang.IllegalArgumentException: tech.[brand].[name]: 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:285)
        at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:158)
        at androidx.work.impl.utils.ForceStopRunnable.forceStopRunnable(ForceStopRunnable.java:185)
        at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:103)
        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)

The stack doesn't reach any of my source code and far as I know I'm not calling any intent in my code so far, pending or otherwise. Does anyone know what's going on?

like image 785
j_wash_BL Avatar asked Sep 19 '25 23:09

j_wash_BL


1 Answers

The androidx.work in the stack trace is WorkManager. As per the WorkManager 2.7.0-alpha02:

Make PendingIntent mutability explicit, to fix a crash when targeting Android 12.

Therefore you should upgrade to the latest version, WorkManager 2.7.1 by adding an explicit dependency on that latest version to the dependencies block of your build.gradle file:

implementation "androidx.work:work-runtime:2.7.1"
like image 174
ianhanniballake Avatar answered Sep 22 '25 12:09

ianhanniballake