此问题可能出现在使用加密共享首选项库(EncryptedSharedPreferences)时。解决方法是在build.gradle中添加以下依赖项:
implementation 'androidx.security:security-crypto:1.0.0'
然后在代码中使用以下语法来创建加密共享首选项:
val masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC) val sharedPreferences = EncryptedSharedPreferences.create( "example", masterKeyAlias, context, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM )
这样就可以避免出现androidx_security_crypto_encrypted_prefs_key_keyset不存在的错误了。