我正在尝试使用 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$1.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 来说已经过时了)