Unexpected behavior with CameraX and SurfaceView in Android 14
Quick question that's been bugging me - I'm updating my dependencies and I'm currently experiencing an issue with CameraX when using a `SurfaceView` for previewing the camera feed in my Android 14 application. The camera preview appears to be stuttering and occasionally freezing, which is not expected behavior. I've followed the official documentation for integrating CameraX, but I suspect that my implementation might be missing something crucial. Here's the code I've implemented for setting up CameraX with a `SurfaceView`: ```kotlin private lateinit var preview: Preview private lateinit var cameraExecutor: ExecutorService override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) cameraExecutor = Executors.newSingleThreadExecutor() setupCamera() } private fun setupCamera() { val surfaceView: SurfaceView = findViewById(R.id.surfaceView) val surfaceHolder = surfaceView.holder surfaceHolder.addCallback(object : SurfaceHolder.Callback { override fun surfaceCreated(holder: SurfaceHolder) { startCamera(holder) } override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {} override fun surfaceDestroyed(holder: SurfaceHolder) {} }) } private fun startCamera(holder: SurfaceHolder) { val cameraProviderFuture = ProcessCameraProvider.getInstance(this) cameraProviderFuture.addListener({ val cameraProvider = cameraProviderFuture.get() preview = Preview.Builder() .build() .also { it.setSurfaceProvider(holder) } // Select back camera as a default val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA try { cameraProvider.unbindAll() cameraProvider.bindToLifecycle(this, cameraSelector, preview) } catch (exc: Exception) { Log.e("CameraX", "Use case binding failed", exc) } }, ContextCompat.getMainExecutor(this)) } ``` I’ve verified that the SurfaceView is set up correctly, and I am not seeing any exceptions being thrown in the logs. However, the stuttering issue seems to be related to the frame rate of the preview. I've also tried adjusting the resolution settings for the `Preview.Builder()`, but that didn't help. The device is a Pixel 7 running Android 14, so I'm not sure if there are any device-specific issues or if I need to adjust the threading model further. Any insights or suggestions on how to smooth out the camera preview would be greatly appreciated! Thanks in advance! I'm working with Kotlin in a Docker container on macOS. Am I missing something obvious? I recently upgraded to Kotlin 3.10. Is there a simpler solution I'm overlooking?