androidandroid-cameraandroid-camerax

CameraX does not work in direct boot mode


When trying to launch the camera in direct boot state using CameraX I get the following error:

Caused by: java.lang.IllegalStateException: CameraX is not configured properly. The most likely cause is you did not include a default implementation in your build such as 'camera-camera2'.
    at androidx.camera.core.CameraX.<init> (CameraX.java:107)
    at androidx.camera.lifecycle.ProcessCameraProvider.getOrCreateCameraXInstance (ProcessCameraProvider.java:196)
    at androidx.camera.lifecycle.ProcessCameraProvider.getInstance (ProcessCameraProvider.java:182)

It happens when I call:

val cameraProviderFuture = ProcessCameraProvider.getInstance(context)

When trying to launch after unlocking the device after restart (i.e. exiting direct boot mode) the code works and camera works fine.

How to fix this?


Solution

  • If the problem is due to the metadata problem @sweak mentioned, another way to handle this can be initializing CameraX through the ProcessCameraProvider#configureInstance and Camera2Config#defaultConfig() API.

    ProcessCameraProvider.configureInstance(Camera2Config.defaultConfig())
    val cameraProviderFuture = ProcessCameraProvider.getInstance(context)