Ben
Ben

Reputation: 1849

Androidx.security with google protobuf

I wanted to implement androidx.security in my app in order to encrypt my sharedpreferences.

I had few problems with building the dependencies of this but eventually the app ran.

Then, when I come to the line where I EncryptedSharedPreferences.create, I get the following error:

java.lang.NoSuchMethodError: No static method registerDefaultInstance(Ljava/lang/Class;Lcom/google/protobuf/GeneratedMessageLite;)V in class Lcom/google/protobuf/GeneratedMessageLite; or its super classes (declaration of 'com.google.protobuf.GeneratedMessageLite' appears in /data/app/com.example.myapp-1/base.apk:classes3.dex)
    at com.google.crypto.tink.proto.AesSivKeyFormat.<clinit>(AesSivKeyFormat.java:248)
    at com.google.crypto.tink.proto.AesSivKeyFormat.newBuilder(AesSivKeyFormat.java:129)
    at com.google.crypto.tink.daead.DeterministicAeadKeyTemplates.createAesSivKeyTemplate(DeterministicAeadKeyTemplates.java:45)
    at com.google.crypto.tink.daead.DeterministicAeadKeyTemplates.<clinit>(DeterministicAeadKeyTemplates.java:38)
    at androidx.security.crypto.EncryptedSharedPreferences$PrefKeyEncryptionScheme.<clinit>(EncryptedSharedPreferences.java:146)
    at com.example.myapp.SignInActivity.lambda$null$1$SignInActivity(SignInActivity.java:129)
    at com.example.myapp.-$$Lambda$SignInActivity$j5WyCkLUVlBZT6WQVBcMkDLDozQ.onComplete(lambda)
    at com.google.android.gms.tasks.zzj.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Any idea how to solve this?

I'm pretty sure it is because I used

exclude group: "com.google.protobuf", module: "protobuf-javalite"

In my build.gradle to make androidx.security work but I can't find any other solution.

Thank you

Upvotes: 2

Views: 2142

Answers (1)

Philio
Philio

Reputation: 4185

This issue was resolved in version 1.0.0-rc02.

See: https://developer.android.com/jetpack/androidx/releases/security

Upvotes: 2

Related Questions