E/AndroidRuntime(15886): java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: java.lang.IllegalArgumentException: br.com.cspautomacao.lazarus_comanda: Targeting U+ (version 34 and above) disallows creating or retrieving a PendingIntent with FLAG_MUTABLE, an implicit Intent within and without FLAG_NO_CREATE and FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT for security reasons. To retrieve an already existing PendingIntent, use FLAG_NO_CREATE, however, to create a new PendingIntent with an implicit Intent use FLAG_IMMUTABLE.
This error started occurring after I updated to Android SDK 34.
My dependencies:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Dependências comuns
implementation fileTree(dir: "libs/comun", include: ['*.aar'])
implementation 'androidx.work:work-runtime-ktx:2.8.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
// Dependências "elgin"
implementation fileTree(dir: 'libs/elgin', include: ['*.aar'])
implementation 'org.apache.commons:commons-lang3:3.9'
implementation 'com.google.code.gson:gson:2.8.6'
}
The error says, starting with Android 14 (API 34), if you have an implicit intent within a PendingIntent object with FLAG_MUTABLE, your app will crash.
If you don't need the FLAG_MUTABLE flag, then just change it to FLAG_IMMUTABLE. However, if your app requires a mutable intent, then I suggest one of the following resolutions:
val implicitIntent = Intent("com.example.app.action.WHATEVER")
val implicitPendingIntent = if (Build.VERSION.SDK_INT >= 34) {
PendingIntent.getBroadcast(this, 0, implicitIntent, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT)
} else {
PendingIntent.getBroadcast(this, 0, implicitIntent, PendingIntent.FLAG_MUTABLE)
}
Make your intent explicit by supplying either the target app's package name or a fully-qualified component class name.
val explicitIntent = Intent("com.example.app.action.WHATEVER")
explicitIntent.setPackage(context.packageName)
// explicitIntent.component = ComponentName("com.example.app", "com.example.app.MainActivity")
val explicitPendingIntent = PendingIntent.getBroadcast(this, 0, explicitIntent, PendingIntent.FLAG_MUTABLE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With