1

When using

androidx.security:security-crypto:1.0.0-rc01

The app runs fine, when using the new

androidx.security:security-crypto:1.0.0-rc02

I get the following

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.app.appm, PID: 12145
    java.lang.NoSuchMethodError: No static method aes256SivTemplate()Lcom/google/crypto/tink/KeyTemplate; in class Lcom/google/crypto/tink/daead/AesSivKeyManager; or its super classes (declaration of 'com.google.crypto.tink.daead.AesSivKeyManager' appears in /data/app/com.app.appm-mak-CE5Ycx65IADcRe9FQw==/base.apk)
        at androidx.security.crypto.EncryptedSharedPreferences$PrefKeyEncryptionScheme.<clinit>(EncryptedSharedPreferences.java:146)
        at com.app.appm.Utils.getPrefs(Utils.java:455)
        at com.app.appm.MainActivity.onCreate(MainActivity.java:184)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/Process: Sending signal. PID: 12145 SIG: 9
Disconnected from the target VM, address: 'localhost:8601', transport: 'socket'

The command that fails is

return EncryptedSharedPreferences.create(
                "app",
                masterKeyAlias,
                context,
                EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
                EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM);

Is that mean I should use a different schema? What about current sharedPreferences file that is in use? It will fail because of that, no? Any idea what can be done? Thanks

Amos
  • 415
  • 1
  • 4
  • 10

1 Answers1

1

This version of the library fixes the problem that was caused by the previous RC version. I can't remember exactly what it was, but it was something to do with the tinc library and dependancy clash with other libraries like Firebase.

To fix the previous issue I had to add the following to my build.gradle:

allprojects {
    configurations.all {
        resolutionStrategy {
            force("com.google.crypto.tink:tink-android:1.3.0-rc1")
        }
    }
}

Removing it again fixed the same crash as you had here.

Philio
  • 3,675
  • 1
  • 23
  • 33
  • Oh, good to know. testing this locally and if it works, I will mark this as answered. Thanks! – Amos May 31 '20 at 17:48
  • Apparently this worked on the emulator but on real devices, the app can't start even after clear cache and data and uninstall... – Amos Jun 04 '20 at 06:47
  • That's weird... I'm testing on a Pixel 3 without issue. – Philio Jun 05 '20 at 00:21
  • The reason is that in production I have this " minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' that's what is causing the problem. in rc01 it works, rc02 fails. – Amos Jun 05 '20 at 05:56
  • Seems more likely that the issue is with your Proguard rules in that case. – Philio Jun 05 '20 at 17:29
  • could be, now the question is what's wrong because in rc01 it works. I have this: -keepattributes SourceFile,LineNumberTable and this -keep class com.app.appm.class1 { *; } (for 3 of my classes) – Amos Jun 05 '20 at 18:11