BiometricPrompt (beta-01) - 调用站点 #3 bootstrap 方法的异常

BiometricPrompt (beta-01) - Exception from call site #3 bootstrap method

我正尝试在我的 Android 应用程序中使用 BiometricPrompt 进行指纹验证。我的代码没有错误,但是当我 运行 它时:

java.lang.BootstrapMethodError: Exception from call site #3 bootstrap method

这是我的 Activity:

 package com.arfmann.accountmanager

import androidx.biometric.*
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import kotlinx.android.synthetic.main.activity_fingerprint.*
import java.util.concurrent.Executors

class FingerprintActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_fingerprint)

        val executor = Executors.newSingleThreadExecutor()
        val activity: FragmentActivity = this // reference to activity
        val biometricPrompt = BiometricPrompt(
            activity,
            executor,
            object : BiometricPrompt.AuthenticationCallback() {

                override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
                    super.onAuthenticationError(errorCode, errString)
                    if (errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON) {
                        // user clicked negative button
                    } else {
                        TODO("Called when an unrecoverable error has been encountered and the operation is complete.")
                    }
                }

                override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
                    super.onAuthenticationSucceeded(result)
                    TODO("Called when a biometric is recognized.")
                }

                override fun onAuthenticationFailed() {
                    super.onAuthenticationFailed()
                    TODO("Called when a biometric is valid but not recognized.")
                }
            })

        val promptInfo = BiometricPrompt.PromptInfo.Builder()
            .setTitle("Set the title to display.")
            .setSubtitle("Set the subtitle to display.")
            .setDescription("Set the description to display")
            .setNegativeButtonText("Negative Button")
            .build()

        authenticateButton.setOnClickListener {
            biometricPrompt.authenticate(promptInfo)
        }
    }
}

这是完整的错误:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.arfmann.accountmanager, PID: 21973 java.lang.BootstrapMethodError: Exception from call site #3 bootstrap method at androidx.biometric.BiometricFragment.(BiometricFragment.java:86) at androidx.biometric.BiometricFragment.newInstance(BiometricFragment.java:187) at androidx.biometric.BiometricPrompt.authenticateInternal(BiometricPrompt.java:681) at androidx.biometric.BiometricPrompt.authenticate(BiometricPrompt.java:658) at com.arfmann.accountmanager.FingerprintActivity$onCreate.onClick(FingerprintActivity.kt:52) at android.view.View.performClick(View.java:6663) at android.view.View.performClickInternal(View.java:6635) at android.view.View.access00(View.java:794) at android.view.View$PerformClick.run(View.java:26199) at android.os.Handler.handleCallback(Handler.java:907) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:216) at android.app.ActivityThread.main(ActivityThread.java:7625) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) Caused by: java.lang.ClassCastException: Bootstrap method returned null at androidx.biometric.BiometricFragment.(BiometricFragment.java:86)  at androidx.biometric.BiometricFragment.newInstance(BiometricFragment.java:187)  at androidx.biometric.BiometricPrompt.authenticateInternal(BiometricPrompt.java:681)  at androidx.biometric.BiometricPrompt.authenticate(BiometricPrompt.java:658)  at com.arfmann.accountmanager.FingerprintActivity$onCreate.onClick(FingerprintActivity.kt:52)  at android.view.View.performClick(View.java:6663)  at android.view.View.performClickInternal(View.java:6635)  at android.view.View.access00(View.java:794)  at android.view.View$PerformClick.run(View.java:26199)  at android.os.Handler.handleCallback(Handler.java:907)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:216)  at android.app.ActivityThread.main(ActivityThread.java:7625)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

我已将正确的依赖添加到 build.gradle:

    implementation 'androidx.biometric:biometric:1.0.0-beta01'
这只发生在 BETA-01 中,在 ALPHA-03 中工作正常

在build.gradle

中设置Java8
compileOptions {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}

我们知道这个问题,并已在 9 月 18 日左右发布的 beta02 版本中解决了这个问题

库已更新为不使用 lambda。