expo: Ejected Android app crashes onBarCodeScanned
🐛 Bug Report
Environment
Expo CLI 3.11.7 environment info:
System:
OS: macOS 10.15.2
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.17.0 - /usr/local/bin/node
Yarn: 1.21.0 - /usr/local/bin/yarn
npm: 6.11.3 - /usr/local/bin/npm
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
npmPackages:
@bugsnag/expo: ^6.4.0 => 6.5.0
expo: ^36.0.0 => 36.0.2
react: 16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz => 0.61.4
react-navigation: ^4.0.10 => 4.0.10
npmGlobalPackages:
expo-cli: 3.11.7
Steps to Reproduce
<Camera
ratio={'16:9'}
style={styles.scanner}
onBarCodeScanned={this.onBarcodeScanned}
/>
When the camera is active, it crashes. It wont crash when i remove the onBarCodeScanned
Expected Behavior
Don’t crash
Actual Behavior
App crashes
Stack trace
java.lang.RuntimeException:
at android.os.AsyncTask$3.done (AsyncTask.java:353)
at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:383)
at java.util.concurrent.FutureTask.setException (FutureTask.java:252)
at java.util.concurrent.FutureTask.run (FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run (AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
at java.lang.Thread.run (Thread.java:764)
Caused by: java.lang.NullPointerException:
at expo.modules.camera.tasks.BarCodeScannerAsyncTask.doInBackground (BarCodeScannerAsyncTask.java:36)
at expo.modules.camera.tasks.BarCodeScannerAsyncTask.doInBackground (BarCodeScannerAsyncTask.java:6)
at android.os.AsyncTask$2.call (AsyncTask.java:333)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run (AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
at java.lang.Thread.run (Thread.java:764)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (2 by maintainers)
I’m also seeing this using expo-camera@11.2.2 and expo-barcode-scanner@10.2.2. This issue should be reopened as it’s not resolved.
same here, app crashs
<CameraScanner onBarCodeScanned={(result) => { if (!scanned) return; handleBarCodeScanned(result); }} ratio={‘1:1’} >
i have this exact same issue with expo-camera crashing when i assign a callback to onBarCodeScanning
You closed it last time too, and the issue still existed. Maybe more people can confirm that it’s fixed first?
Hey, based on #8847 I figured that this happens when the
expo-barcode-scanner
is not installed. As a workaround, I managed to prevent the crashes by installingexpo-barcode-scanner
withexpo install expo-barcode-scanner
.I’ve ran into this multiple times today. The only way to resolve it is to completely clear all native parts, and even then I can’t tell why it starts showing again (which it will):
<Camera style={{ flex: 1 }} />
: it will workonBarCodeScanned={console.log}
Now, it might work, but most likely it will start crashing (instantly, when the first frame shows up). Exact same crash log.
If it doesn’t crash now, it seems that adding other dependencies will at some point “trigger” the crash and now it will keep on happening. There is definitely something wrong with the native code.
Here the scanner is
null
:https://github.com/expo/expo/blob/8d441c7e9b081cfdd6a45edc165251d7273225a0/packages/expo-camera/android/src/main/java/expo/modules/camera/tasks/BarCodeScannerAsyncTask.java#L36
Which means that it must never be initialised, or not provided here:
https://github.com/expo/expo/blob/284d4840c02ae895f64a4fef994902027d51e614/packages/expo-camera/android/src/main/java/expo/modules/camera/ExpoCameraView.java#L255
It’s existence is not checked here (which might not be the actual issue. It’s much more likely that it’s dereferenced or that the provider doesn’t provide anything):
https://github.com/expo/expo/blob/284d4840c02ae895f64a4fef994902027d51e614/packages/expo-camera/android/src/main/java/expo/modules/camera/ExpoCameraView.java#L129
Reproducible example? Not quite – or at least not consistently, but it all points to the same issue. I can consistently make it break, once I can make it break, even when removing all the other code except for the
Camera
component.git clone
: https://github.com/brentvatne/camera-exampleyarn
yarn android
It might, or might not work out of the box. The first time I had it crash within seconds. The second time it took a while. The third project was instant again, but there I added a few native modules.
In the end I ended up with replacing his code with:
Which then shows up correctly, and when I press the button it blows up (as it starts to scan).
same here.
Same for me
I havent got this issue anymore so closing it.
This was happening for me even with
expo-barcode-scanner
installed. I haven’t looked at this since. Perhaps it was a mismatch in versions.