java.lang.BootstrapMethodError: Exception from call site #2 bootstrap method on CameraX (1.0.0-alpha06)

java.lang.BootstrapMethodError: Exception from call site #2 bootstrap method on CameraX (1.0.0-alpha06)

我正在尝试使用 CameraX API 获取照片,但在我更新到新的 API 版本 1.0.0-alpha06 后,它开始在

上崩溃
CameraX.bindToLifecycle(...)

方法。

错误日志为:

Process: com.aximetria.aximetria.debug, PID: 2629
    java.lang.BootstrapMethodError: Exception from call site #2 bootstrap method
        at androidx.camera.core.Preview.updateListener(Preview.java:368)
        at androidx.camera.core.Preview.updateOutput(Preview.java:586)
        at androidx.camera.core.Preview.updateConfigAndOutput(Preview.java:363)
        at androidx.camera.core.Preview.onSuggestedResolutionUpdated(Preview.java:524)
        at androidx.camera.core.UseCase.updateSuggestedResolution(UseCase.java:408)
        at androidx.camera.core.CameraX.calculateSuggestedResolutions(CameraX.java:684)
        at androidx.camera.core.CameraX.bindToLifecycle(CameraX.java:195)
        at com.aximetria.aximetria.ui.main.profile.avatar.TakeAvatarPhotoFragment.initCamera(TakeAvatarPhotoFragment.kt:169)
        at com.aximetria.aximetria.ui.main.profile.avatar.TakeAvatarPhotoFragment.initCamera$default(TakeAvatarPhotoFragment.kt:117)
        at com.aximetria.aximetria.ui.main.profile.avatar.TakeAvatarPhotoFragment$onViewCreated.onPermissionsChecked(TakeAvatarPhotoFragment.kt:55)
    ...

我的代码是:

    private fun initCamera(reverseFacing: Boolean = false) {
        ...

        val previewConfig = PreviewConfig.Builder()
                .setTargetAspectRatio(AspectRatio.RATIO_4_3)
                .setLensFacing(lensFacing)
                .build()

        val preview = Preview(previewConfig)
        preview.setOnPreviewOutputUpdateListener { previewOutput ->
            val parent = binding.preview.parent as ViewGroup
            parent.removeView(binding.preview)
            parent.addView(binding.preview, 0)
            binding.preview.surfaceTexture = previewOutput.surfaceTexture
        }

        val captureConfig = ImageCaptureConfig.Builder()
                .setFlashMode(flashMode)
                .setLensFacing(lensFacing)
                .build()

        val capture = ImageCapture(captureConfig)

        binding.takeAPhoto.setOnClickListener {
            ...
            val imageFile = createTempFile(System.currentTimeMillis().toString(), ".jpg")
            capture.takePicture(imageFile, this, object : ImageCapture.OnImageSavedListener {
                override fun onImageSaved(file: File) {
                    ...
                }

                override fun onError(imageCaptureError: ImageCapture.ImageCaptureError, message: String, cause: Throwable?) {
                    ...
                }
            })
        }

        CameraX.bindToLifecycle(this, capture, preview)
    }

有谁知道是什么导致了这次崩溃?我在文档中看不到任何相关信息(此时对于 CameraX 已经过时)

作为@a-local-nobody,@stéphane-péchard 和@yoonhok 正确地指出了库的 alpha-6 版本中的错误。回滚到 alpha-05 也消除了我的崩溃。

将此添加到 gradle。

CameraX needs some methods that are part of Java 8, so we need to set our compile options accordingly. At the end of the android block, right after buildTypes, add the following:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

我已通过将 Java8 添加到应用 build.gradle

来解决此问题
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = "1.8"
}

将以下行添加到 build.gradle(:app) 文件中:

android{

  compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }    
}