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

Peter Staranchuk picture Peter Staranchuk · Oct 21, 2019 · Viewed 13.8k times · Source

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)

Answer

Martynas B picture Martynas B · Oct 29, 2019

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
}