Skip to content

Conversation

alihassan143
Copy link

No description provided.

@alihassan143 alihassan143 changed the title Removed camera plugin crashes on some devices and improved initization process fix: fixed camera crashes on some devices Jul 22, 2025
@navaronbracke
Copy link
Collaborator

Do you have a stacktrace for the actual crash?

@alihassan143
Copy link
Author

Do you have a stacktrace for the actual crash?


Exception java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:613)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:947)
Caused by java.lang.reflect.InvocationTargetException:
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:603)
Caused by java.util.concurrent.ExecutionException:
  at androidx.concurrent.futures.AbstractResolvableFuture.getDoneValue (AbstractResolvableFuture.java:518)
  at androidx.concurrent.futures.AbstractResolvableFuture.get (AbstractResolvableFuture.java:475)
  at androidx.concurrent.futures.CallbackToFutureAdapter$SafeFuture.get (CallbackToFutureAdapter.java:199)
  at androidx.camera.core.impl.utils.futures.FutureChain.get (FutureChain.java:155)
  at androidx.camera.core.impl.utils.futures.ChainingListenableFuture.get (ChainingListenableFuture.java:105)
  at dev.steenbakker.mobile_scanner.MobileScanner.start$lambda$16 (MobileScanner.java:385)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:223)
  at android.app.ActivityThread.main (ActivityThread.java:7950)
Caused by y.V:
  at androidx.camera.core.InitializationException.<init> (InitializationException.java:36)
  at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2 (CameraX.java:433)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at java.lang.Thread.run (Thread.java:923)
Caused by y.r: Device reporting less cameras than anticipated. On real devices: Retrying initialization might resolve temporary camera errors. On emulators: Ensure virtual camera configuration matches supported camera features as reported by PackageManager#hasSystemFeature. Available cameras: 0
  at androidx.camera.core.CameraUnavailableException.<init> (CameraUnavailableException.java:102)
  at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2 (CameraX.java:433)

1 similar comment
@alihassan143
Copy link
Author

Do you have a stacktrace for the actual crash?


Exception java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:613)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:947)
Caused by java.lang.reflect.InvocationTargetException:
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:603)
Caused by java.util.concurrent.ExecutionException:
  at androidx.concurrent.futures.AbstractResolvableFuture.getDoneValue (AbstractResolvableFuture.java:518)
  at androidx.concurrent.futures.AbstractResolvableFuture.get (AbstractResolvableFuture.java:475)
  at androidx.concurrent.futures.CallbackToFutureAdapter$SafeFuture.get (CallbackToFutureAdapter.java:199)
  at androidx.camera.core.impl.utils.futures.FutureChain.get (FutureChain.java:155)
  at androidx.camera.core.impl.utils.futures.ChainingListenableFuture.get (ChainingListenableFuture.java:105)
  at dev.steenbakker.mobile_scanner.MobileScanner.start$lambda$16 (MobileScanner.java:385)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:223)
  at android.app.ActivityThread.main (ActivityThread.java:7950)
Caused by y.V:
  at androidx.camera.core.InitializationException.<init> (InitializationException.java:36)
  at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2 (CameraX.java:433)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at java.lang.Thread.run (Thread.java:923)
Caused by y.r: Device reporting less cameras than anticipated. On real devices: Retrying initialization might resolve temporary camera errors. On emulators: Ensure virtual camera configuration matches supported camera features as reported by PackageManager#hasSystemFeature. Available cameras: 0
  at androidx.camera.core.CameraUnavailableException.<init> (CameraUnavailableException.java:102)
  at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2 (CameraX.java:433)

@navaronbracke
Copy link
Collaborator

Device reporting less cameras than anticipated. On real devices: Retrying initialization might resolve temporary camera errors. On emulators: Ensure virtual camera configuration matches supported camera features as reported by PackageManager#hasSystemFeature. Available cameras: 0
  at androidx.camera.core.CameraUnavailableException.<init> (CameraUnavailableException.java:102)
  at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2 (CameraX.java:433)

That looks like a device specific configuration issue? What devices is this happening on?

@navaronbracke
Copy link
Collaborator

navaronbracke commented Aug 5, 2025

I think all we need here is

                if (cameraProvider!!.availableCameraInfos.isEmpty()) {
                    mobileScannerErrorCallback(NoCamera())
                    // Handle no camera scenario
                    return@addListener
                }

after line 392: https://github.com/juliansteenbakker/mobile_scanner/blob/develop/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt#L392

We check if the camera provider is null, but not if it has no cameras during initialization.

The rest of of the code in this PR seems irrelevant to the fix.

@alihassan143
Copy link
Author

I think all we need here is

                if (cameraProvider!!.availableCameraInfos.isEmpty()) {
                    mobileScannerErrorCallback(NoCamera())
                    // Handle no camera scenario
                    return@addListener
                }

after line 392: https://github.com/juliansteenbakker/mobile_scanner/blob/develop/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt#L392

We check if the camera provider is null, but not if it has no cameras during initialization.

The rest of of the code in this PR seems irrelevant to the fix.

but we should need to handle null checks also other wise it cause issue

@alihassan143
Copy link
Author

Device reporting less cameras than anticipated. On real devices: Retrying initialization might resolve temporary camera errors. On emulators: Ensure virtual camera configuration matches supported camera features as reported by PackageManager#hasSystemFeature. Available cameras: 0
  at androidx.camera.core.CameraUnavailableException.<init> (CameraUnavailableException.java:102)
  at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2 (CameraX.java:433)

That looks like a device specific configuration issue? What devices is this happening on?

realme RED8F6

@navaronbracke
Copy link
Collaborator

The stacktrace you provided does not mention any NullPointerExceptions, so that is not the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants