I am migrating to cameraX and faced the exception
androidx.camera.core.InitializationException: java.lang.RuntimeException: Error retrieving camcorder profile params
The error-log states that this error is thrown when calling
cameraProvider = cameraProviderFuture.get()
I cannot reproduce this error on any device.
I initialize the Camera here:
private fun initCameraProvider() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(this) //Error is thrown here
cameraProviderFuture.addListener(Runnable {
cameraProvider = cameraProviderFuture.get()
val metrics = DisplayMetrics().also {
previewView?.display?.getRealMetrics(it)
}
val screenAspectRatio = ImageUtils.aspectRatio(metrics.widthPixels, metrics.heightPixels)
val rotation = previewView?.display?.rotation ?: 0
preview = Preview.Builder()
.setTargetAspectRatio(screenAspectRatio)
.setTargetRotation(rotation)
.build()
analyzer = BarcodeAnalyzer(previewView, overlay) { onSuccess(it) }
val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
imageAnalyzer = ImageAnalysis.Builder()
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.setTargetAspectRatio(screenAspectRatio)
.build()
.also {
it.setAnalyzer(cameraExecutor, analyzer)
}
val useCaseGroup = UseCaseGroup.Builder()
.addUseCase(preview)
.addUseCase(imageAnalyzer)
.build()
try {
cameraProvider?.unbindAll()
preview.setSurfaceProvider(previewView?.surfaceProvider)
camera = cameraProvider?.bindToLifecycle(this, cameraSelector, useCaseGroup)
} catch (exc: Exception) {
Log.e(TAG, "Use case binding failed", exc)
}
}, ContextCompat.getMainExecutor(this))
}
Update: (24/03/2021 - dd/MM/yyyy)
The bug has been fixed in CameraX 1.0.0-rc04 and 1.0.0-alpha23. Just update the dependencies to this version or above
Update: (22/03/2021 - dd/MM/yyyy)
There should be a new CameraX release soon which fixes the problem, in the mean time you can apply this workaround:
// CameraX core library
def camerax_version = '1.0.0-rc03'
implementation("androidx.camera:camera-core") {
version {
strictly "$camerax_version"
}
because "Force use 1.0.0-rc03"
}
// CameraX Camera2 extensions
implementation("androidx.camera:camera-camera2") {
version {
strictly "$camerax_version"
}
because "Force use 1.0.0-rc03"
}
// CameraX Lifecycle library
implementation("androidx.camera:camera-lifecycle") {
version {
strictly "$camerax_version"
}
because "Force use 1.0.0-rc03"
}
implementation "androidx.camera:camera-extensions:1.0.0-alpha22"
implementation 'androidx.camera:camera-view:1.0.0-alpha22'
as described here
Currently there is bug in CameraX affecting (at least) Samsung S20+ and Galaxy Note 10+
Here the issue link for updates: https://issuetracker.google.com/issues/181599852
I got the same issue using camerax version 1.1.0-alpha01 on Samsung s20+ and note 10+. Try to downgrade to 1.0.0-beta11.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With