3

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 ?

Rohan Chavda
  • 63
  • 1
  • 4
  • If you are certain this is the code that triggers that error, then you will either need to drop your `targetSdkVersion` back to 30 for a while or stop using `EncryptedSharedPreferences`. `androidx.security` has not been updated in nearly a year, and it pre-dates this new Android 12 restriction. – CommonsWare Nov 29 '21 at 12:55

2 Answers2

2

Try to add below line into your :app (module-level) build.gradle dependencies:

implementation 'androidx.work:work-runtime-ktx:2.7.1'
hata
  • 11,633
  • 6
  • 46
  • 69
2

Adding this dependency solved the issue for me.

implementation 'androidx.work:work-runtime-ktx:2.7.1'
Aditya Verma
  • 120
  • 2
  • 10