Secured Android SharedPreferences Error: 'Caused by: java.lang.RuntimeException: Field keySize_ for…'

删除回忆录丶 提交于 2020-07-08 11:08:42

问题


In an Android Kotlin project, I implemented EncryptedSharedPreference feature based on this link using the androidx.security library and it worked well in debug mode. But in release mode, I keep getting this error

  java.lang.ExceptionInInitializerError
    at com.package_name.i.a.f(:46)
    at com.package_name.i.a.j(:52)
    at com.package_name.i.a.e(:82)
    at com.package_name.MyApplication.onCreate(:37)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
    at android.app.ActivityThread.-wrap1(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: java.lang.RuntimeException: Field keySize_ for k.a.d.a.h0.u not found. Known fields are [private int k.a.d.a.h0.u.i, private static final k.a.d.a.h0.u k.a.d.a.h0.u.j, private static volatile k.a.d.a.i0.a.a1 k.a.d.a.h0.u.k]
    at k.a.d.a.i0.a.v0.n0(:608)

Please kindly share your ideas on how to solve this error.


回答1:


This bug is related to Minify Enabled, which most likely causes some values to be removed.

A bug is reported already, you can track it here:

https://issuetracker.google.com/issues/157983099




回答2:


Something is wrong with the rc2 version of android crypto of may 20. So it is better to use 1.0.0-alpha02 in your gradle file. Remember, takes care with dependencies which are not in rc. You can also fix the issue with a proguard rules (see comment of Sebas LG).

dependencies {
    implementation "androidx.security:security-crypto:1.0.0-alpha02"
}

Official documentation : https://developer.android.com/jetpack/androidx/releases/security

Linked commits : https://android.googlesource.com/platform/frameworks/support/+log/f66cdf1658639bd74ae850dfe3c1f5bb72eaebe6..6be101c2241593fee3ef9ab4e1fb337b485f2f9a/security/crypto



来源:https://stackoverflow.com/questions/62135766/secured-android-sharedpreferences-error-caused-by-java-lang-runtimeexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!