š InitializationException - Device reporting less cameras than anticipated
What's happening?
I am encountering a crash reported in Crashlytics, related to androidx.camera.core.InitializationException. The issue seems to occur when the app attempts to initialize the camera, and it reports fewer cameras than expected, resulting in a CameraUnavailableException. This crash happens on real devices, and it mentions retrying initialization. However, I cannot reproduce the issue locally on my test devices, so Iām unable to investigate further in a controlled environment.
Reproduceable Code
const QRCodeScanner: React.FC<QRCodeScannerProps> = ({
onCodeScanned,
loading,
handlePermissionBlocked,
}) => {
const device = useCameraDevice('back');
const camera = useRef<Camera>(null);
const isFocused = useIsFocused();
const appState = useAppState();
const [cameraReady, setCameraReady] = useState(false);
const {onLayout, layout} = useLayout();
const hasPermission = useCameraPermissions(handlePermissionBlocked);
const codeScanner = useCodeScanner({
codeTypes: ['qr'],
onCodeScanned,
});
const isActive = isFocused && appState === 'active' && !!layout && !loading;
const isScanning = isActive && cameraReady;
const onError = (err: CameraRuntimeError | string) =>
Analytics.logError(err, 'Camera error');
return device && hasPermission ? (
<View style={styles.container} onLayout={onLayout}>
{isScanning ? (
<QRMask
containerHeight={layout.height}
containerWidth={layout.width}
/>
) : null}
{!isScanning ? (
<View style={styles.loaderContainer}>
<DefaultLoader />
</View>
) : null}
<Camera
ref={camera}
onError={onError}
photo={false}
device={device}
codeScanner={codeScanner}
isActive={isActive}
style={StyleSheet.absoluteFill}
onPreviewStarted={() => setCameraReady(true)}
onStopped={() => setCameraReady(false)}
/>
</View>
) : null;
};
Relevant log output
Crashlytics report:
Fatal Exception: androidx.camera.core.InitializationException
androidx.camera.core.CameraUnavailableException: 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
androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2$androidx-camera-core-CameraX (CameraX.java:433)
Camera Device
I cannot provide the JSON for the camera device since the issue occurs in production and I cannot reproduce it locally.
Device
The crash affects multiple devices, with the following breakdown: Motorola (69%) Samsung (17%) Xiaomi (14%). Operating system versions: Android 11 (62%) Android 13 (21%) Android 12 (17%).
VisionCamera Version
4.5.2
Can you reproduce this issue in the VisionCamera Example app?
No, I cannot reproduce the issue in the Example app
Additional information
- [ ] I am using Expo
- [ ] I have enabled Frame Processors (react-native-worklets-core)
- [X] I have read the Troubleshooting Guide
- [X] I agree to follow this project's Code of Conduct
- [X] I searched for similar issues in this repository and found none.
Guten Tag, Hans here š»
Thanks for your detailed report! It sounds like a tricky issue, and I appreciate you trying to gather as much information as possible. However, we need more logs to help mrousavy effectively troubleshoot this problem. Please capture the logs using adb logcat when the crash occurs on the real devices, so we can get better insights into what's happening.
If you need help with gathering the logs, feel free to ask! The more data we have, ze easier it will be to find a solution.
Looking forward to your update!
Note: If you think I made a mistake, please ping
@mrousavyto take a look.
Hey, I have same problem on production, multiple crashes in crashlytics (its small % of users, but enough to be one of main reason for our crashes currently). Maybe my information will help you somehow to debug this.
"react-native": "0.73.8",
"react-native-vision-camera": "4.5.0"
I add stacktarce from one of crashes. stacktrace.txt
Name of error is androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2$androidx-camera-core-CameraX (CameraX.java:369). Mostly (46%) its Xiaomi devices, different androids.
Hi, same problem here in production too.
"react-native": "0.74.1",
"react-native-vision-camera": "4.3.2",
In Crashlytics there's this error description:
Well, Camera APIs on Android suck.
Started seing this out of the sudden on Android 9 on 4.5.2, rn 0.75.3.
Can reproduce it locally on Pixel 4XL emulator running Android 9. @mrousavy do you need any logs or screw camera apis š?
Some extra information around the bug, Simulator Pixel 4XL Android 9, same thing happens on real devices though.
- Open device camera app
- open your app
- try to pick a photo, throws:
[session/recoverable-error: An unknown error occurred while creating the Camera Session, but the Camera can recover from it.] ERROR [device/camera-already-in-use: The given Camera Device is already in use!] - Close your app
- try to open device camera app again: Android throws:
Camera error Can't connect to cameraso it seems it brakes Android system too. - only way to recover device camera app is to cold boot the emulator
stack:
FATAL EXCEPTION: pool-26-thread-2 (Ask Gemini)
Process: com.xxxxx, PID: 10365
androidx.camera.core.InitializationException: androidx.camera.core.CameraUnavailableException: 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.CameraX.lambda$initAndRetryRecursively$2$androidx-camera-core-CameraX(CameraX.java:433)
at androidx.camera.core.CameraX$$ExternalSyntheticLambda2.run(D8$$SyntheticClass:0)
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:764)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@81d901b, java.util.concurrent.ThreadPoolExecutor@660c5b8[Running, pool size = 2, active threads = 1, queued tasks = 0, completed tasks = 2]]
Caused by: androidx.camera.core.CameraUnavailableException: 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
edit: tried with 4.5.3 (with [email protected]) and it throws the same error.
Hello guys, I just found a way to reproduce the issue.
- From Edit Android Emulator -> Show Advanced Settings -> Camera: Front -> None and Back -> None
- Run your app on that emulator and the issue will appear
Thanks guys for pointing nearly all the versions that have the issue. As a result I use react-native-vision-camera: 4.2.1.
Below is my final version in package.json
"dependencies": {
"react": "18.2.0",
"react-native": "0.73.9",
"react-native-reanimated": "3.15.2",
"react-native-vision-camera": "4.2.1",
},
Hope it can help.
Same issue with react-native-vision-camera 4.5.2
same issue
Same here:
react-native: 0.73.4
react-native-vision-camera: ^4.5.2
androidx.camera.core.InitializationException: androidx.camera.core.CameraUnavailableException: 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.CameraX.lambda$initAndRetryRecursively$2$androidx-camera-core-CameraX(CameraX.java:433)
at androidx.camera.core.CameraX$$ExternalSyntheticLambda0.run(Unknown:12)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
Caused by: androidx.camera.core.CameraUnavailableException: 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.CameraX.lambda$initAndRetryRecursively$2$androidx-camera-core-CameraX(CameraX.java:433)
at androidx.camera.core.CameraX$$ExternalSyntheticLambda0.run(Unknown:12)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
same problem
same issue
"react-native": "0.73.9", "react-native-vision-camera": "^4.5.2"
any help ?
Same issue here.
Same issue here...
We are having the same issue here:
- react-native-vision-camera: 4.5.0;
- react-native: 0.74.5;
any updates ?
any updates ?
Unfortunately, no one can reproduce the error concisely. :(
Has the camerax version has been updated to 1.4.0 ?
I am also facing this issue post version update & have raised it here. Please upvote if the issue is same
Have raised it here https://issuetracker.google.com/issues/383220395
Has the camerax version has been updated to 1.4.0 ?
https://github.com/mrousavy/react-native-vision-camera/blob/54df86ace1716039f690e865c97f29f87dfe43b7/package/android/build.gradle#L185-L192
@mrousavy We are using version 4.6.1, and our build.gradle file is the same as the one you provided, 1.5.0-alpha03. However, some phones are still reporting this error.
still same
still same, we get this error on some devices. do you have any suggestions for a solution?
Still same. Is there a solution for this?
any updates ? thie issue happen today for 15 user.
I am also getting this crash in firebase crashlytics
So do i
+1 Same issue
i am also getting the same error. -- i am not able to reproduce exactly but getting this log from some devices listed below with OS version
- here's some stacktrace from dynatrace:
details: "react-native": "0.75.4", "react-native-vision-camera": "^4.5.3",
Devices P30 Pro (46.6 %) Galaxy A51 (26.2 %) HUAWEI nova 5T (3.4 %) Infinix HOT 40i (2.43 %) Others (21.4 %)
Operating system Android 10 (50 %) Android 13 (31.1 %) Android 11 (6.31 %) Android 12 (4.37 %) Others (8.25 %)
`androidx.camera.core.InitializationException: androidx.camera.core.CameraUnavailableException: 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.CameraX.lambda$initAndRetryRecursively$2$androidx-camera-core-CameraX(CameraX.java:433)
at
androidx.camera.core.CameraX$$ExternalSyntheticLambda2.run(D8$$SyntheticClass:0)
at
java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at
java.lang.Thread.run(Thread.java:784)`
any updates ?!