skip to Main Content

When launching an activity my app crashes at getEncryptedSharedPrefs:

    if(getEncryptedSharedPrefs().getString("pinSettingsLogin", "")!!.isEmpty()){
        getEncryptedSharedPrefs().edit()
            .putString("pinSettingsLogin" , "0000")
            .apply()
    }

With this error:

Caused by: com.google.crypto.tink.shaded.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).

Weird thing is, this if statement works on Android 10 and 11 but not on Android 12. This if statement is here because in the ‘if’ below I check if the pinSettingsLogin = 0000 so that It goes to a new activity by it self.

    if(getEncryptedSharedPrefs().getString("pinSettingsLogin", "").equals("0000")){
        val i = Intent(this, SettingsActivity::class.java)
        startActivity(i)
        overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left)
    }

3

Answers


  1. Have you tried clearing the app’s cache?

    This might fix the problem!

    Login or Signup to reply.
  2.  implementation "androidx.security:security-crypto:1.1.0-alpha04"
    

    Initialize sharedpreference like given in documentation:

     val keyGenParameterSpec = MasterKey.Builder(activity)
    .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
    .build()
    
            val sharedPref : SharedPreferences = EncryptedSharedPreferences
    .create(activity,"secret_shared_prefs", keyGenParameterSpec, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
                EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM)
    
    Login or Signup to reply.
  3. This is a bug from EncryptedSharedPreferences, the issue happens on the initialization of the EncryptedSharedPreferences.

    Check it out here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search