kotlin Android密钥库在Android即时应用程序中崩溃

xqkwcwgp  于 2022-11-30  发布在  Kotlin
关注(0)|答案(1)|浏览(184)
    • bounty将在7天后过期**。回答此问题可获得+50的声望奖励。Rupesh正在寻找来自知名来源的答案
val masterKey =
            MasterKey
            .Builder(applicationContext)
            .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
            .build()

在Instant App中运行此代码会使我的应用崩溃,并显示以下堆栈跟踪:

2020-12-21 13:07:29.654 28949-28949/com.example.instantappandroidkeystore E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.instantappandroidkeystore, PID: 28949
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.instantappandroidkeystore/com.example.instantappandroidkeystore.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'int android.security.keystore.IKeystoreService.exist(java.lang.String, int)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3448)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7814)
        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:1068)
     Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int android.security.keystore.IKeystoreService.exist(java.lang.String, int)' on a null object reference
        at android.security.KeyStore.contains(KeyStore.java:408)
        at android.security.keystore.AndroidKeyStoreSpi.engineContainsAlias(AndroidKeyStoreSpi.java:1038)
        at java.security.KeyStore.containsAlias(KeyStore.java:1293)
        at androidx.security.crypto.MasterKeys.keyExists(MasterKeys.java:154)
        at androidx.security.crypto.MasterKeys.getOrCreate(MasterKeys.java:96)
        at androidx.security.crypto.MasterKey$Builder.buildOnM(MasterKey.java:357)
        at androidx.security.crypto.MasterKey$Builder.build(MasterKey.java:314)
        at com.example.instantappandroidkeystore.MainActivity.onCreate(MainActivity.kt:32)
        at android.app.Activity.performCreate(Activity.java:7955)
        at android.app.Activity.performCreate(Activity.java:7944)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3423)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:237) 
        at android.app.ActivityThread.main(ActivityThread.java:7814) 
        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:1068) 

我没有运气在StackOverflow中找到这个问题,但我在Google Issue Tracker中找到了它,但没有回应。所以我创建了一个问题提交给Google,并提供了更多信息。https://issuetracker.google.com/issues/176085956
是否有人遇到过此问题并能够解决它。
我的工作环境是:

  • Mac操作系统10.15.7版
  • Android Studio 4.0.1
  • 三星A70
  • 安卓10版
s3fp2yjn

s3fp2yjn1#

虽然这在www.example.com论坛上没有正式记录developer.android,但看起来Android密钥库访问对即时应用程序是有限制的。
这是相当奇怪的是,密钥库是有限的,没有android文档解释它。我不知道在一个替代访问密钥库,因为我们有很多依赖于我们的常规应用程序(非即时)密钥库,我想不出一个更好的选择。期待建议!

相关问题