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

妖精的绣舞 提交于 2020-05-12 15:27:36

问题


I am trying to use CameraX API to fetch photo, but after I updated to new API version 1.0.0-alpha06 it started to crash on

CameraX.bindToLifecycle(...)

method.

The log of error is:

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)
    ...

My code is:

    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)
    }

Is anyone know what caused this crash? I cannot see any related information in documentation (which by this time is out of date for CameraX)


回答1:


Add this in 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
}



回答2:


I have fixed this issue by adding Java8 to app build.gradle

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = "1.8"
}



回答3:


As @a-local-nobody, @stéphane-péchard and @yoonhok rightly said the bug in alpha-6 version of library. Roll back to alpha-05 also removed crashes in my case.




回答4:


Add the following lines into build.gradle(:app) file :

android{

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


来源:https://stackoverflow.com/questions/58482498/java-lang-bootstrapmethoderror-exception-from-call-site-2-bootstrap-method-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!