将androidx biometric更新为1.0.0-alpha04后,Android崩溃

时间:2019-04-15 06:01:32

标签: android kotlin androidx biometrics android-biometric-prompt

一切都适合'androidx.biometric:biometric:1.0.0-alpha03',但是当我使用最新的'androidx.biometric:biometric:1.0.0-alpha04'构建项目并调用myBiometricPrompt.authenticate(promptInfo)时,会抛出此异常:FragmentManager is already executing transactions

这是堆栈跟踪:

 java.lang.IllegalStateException: FragmentManager is already executing transactions
        at androidx.fragment.app.FragmentManagerImpl.ensureExecReady(FragmentManager.java:2207)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2267)
        at androidx.fragment.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:814)
        at androidx.biometric.BiometricPrompt.authenticateInternal(BiometricPrompt.java:525)
        at androidx.biometric.BiometricPrompt.authenticate(BiometricPrompt.java:465)
        at com.my.app.ui.LoginFragment.handleTouchIdAuth(LoginFragment.kt:161)
        at com.my.app.ui.LoginFragment.onViewCreated(LoginFragment.kt:62)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1471)
        at androidx.fragment.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2646)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2416)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2372)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2466)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
        at android.app.Activity.performStart(Activity.java:7157)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        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)

有人知道发生了什么事和怎么做吗?现在,我将坚持使用 1.0.0-alpha03

版本

谢谢!

3 个答案:

答案 0 :(得分:4)

通过提供第二个构造函数,可以在androidx.biometric:biometric:1.0.0-beta01中解决此问题。在此版本之前,我通过恢复为alpha03来解决了该问题,但是现在有一个实际的解决方案。

您可以找到beta01发行说明here

  

我们为BiometricPrompt引入了第二个构造函数,该构造函数允许   它将托管在Fragment中(与现有的构造方法相对,   这需要一个FragmentActivity)。

您可以找到新的BiometricPrompt构造函数文档here

BiometricPrompt(Fragment fragment, Executor executor, BiometricPrompt.AuthenticationCallback callback)

要修复,请按照以下简单步骤操作:

  1. 将build.gradle更改为使用生物识别版本1.0.0-beta01
  2. 使用新的构造函数。简而言之,将第一个参数更改为片段而不是活动。请在下面查看我的代码更改:

    val biometricPrompt = BiometricPrompt(activity!!, executor, callback)
    // Change the above line to the below line
    val biometricPrompt = BiometricPrompt(this, executor, callback)
    

答案 1 :(得分:3)

alpha04似乎有问题,恢复为alpha03即可解决。 猜猜我们将不得不等待alpha05才能升级。

只希望Google等到生物识别库超出alpha版本后才弃用指纹库...

答案 2 :(得分:-1)

该问题在最新版本androidx.biometric:biometric:1.0.0-beta01中仍然存在。

要修复此问题,请显示处理程序中的biometricPrompt:

    val promptInfo = BiometricPrompt.PromptInfo.Builder()
            .setTitle(fragmentActivity.getString(title))
            .setNegativeButtonText(fragmentActivity.getString(negativeButtonText))
            .build()
    val biometricPrompt = BiometricPrompt(...)

    // display biometricPrompt from handler
    Handler().post {
        biometricPrompt.authenticate(promptInfo)
    }