Search code examples
androidsharedpreferencesencrypted-shared-preference

security-crypto: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent


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.

stacktrace:

com.google.crypto.tink.shaded.protobuf.FieldType$Collection. (FieldType.java:337) androidx.security.crypto.EncryptedSharedPreferences$PrefKeyEncryptionScheme. (EncryptedSharedPreferences.java:148) PreferenceHelper$Companion.init (PreferenceHelper.kt:41)

this is how i initialize SharedPreferences:

private lateinit var preferences: SharedPreferences

fun init(context: Context) {
     val mainKey = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
     preferences = EncryptedSharedPreferences.create(
                SHARED_PREF_KEY,
                mainKey,
                context,
                EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,   <- this is the 41 line number, where its crashing
                EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
         )

 }

Any help please ?


Solution

  • Adding this dependency solved the issue for me.

    implementation 'androidx.work:work-runtime-ktx:2.7.1'