Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 613
Peter Staranchuk Avatar asked Oct 21 '19 08:10

Peter Staranchuk


3 Answers

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
}
like image 193
Martynas B Avatar answered Oct 30 '22 07:10

Martynas B


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"
}
like image 21
rajahsekar Avatar answered Oct 30 '22 08:10

rajahsekar


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

android{

  compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }    
}
like image 4
MEGHA DOBARIYA Avatar answered Oct 30 '22 07:10

MEGHA DOBARIYA