Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio doesnt recognise EncryptedSharedPreferences import

So I'm trying to create the Encrypted Shared prefs as shown in the dev android side : https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences#inherited-methods And android studio doesn't seem to recognize it all all. My min skd is 23 is that reason form what I understand so far androidx doesnt require the newest android version?

Tried clean rebuild build etc. Tried migrating to androidx from Android studio menu ( getting the message of no usages found in project but I do have a few imports for androidx as I understood after checking it out)

import androidx.security.crypto.EncryptedSharedPreferences;


 String masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
        SharedPreferences sharedPreferences = EncryptedSharedPreferences.create(
                "secret_shared_prefs",
                masterKeyAlias,
                context,
                EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
                EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
        );

//doesnt recognise MasterKeys nor EncryptedSharedPreferences classes
like image 573
Michael Mouzakitis Avatar asked Sep 21 '25 05:09

Michael Mouzakitis


1 Answers

As per the androidx.security Declaring dependencies documentation, you need to add the dependency on the library:

dependencies {
    def security_version = "1.0.0-alpha02"
    implementation "androidx.security:security-crypto:$security_version"
}
like image 50
ianhanniballake Avatar answered Sep 22 '25 21:09

ianhanniballake