ideacreation / react-native-barcodescanner

A barcode scanner component for react native - not maintained anymore - use react-native-camera
MIT License
537 stars 162 forks source link

Occasional crash on physical device while the scanner is up #27

Open frankliu81 opened 8 years ago

frankliu81 commented 8 years ago

I am hitting intermittent crash while the scanner is up.

I am running a 2013 Nexus 4, upgraded to Android 5. The scanner works, but every once a while when the scanner is up, the whole screen will go completely black, and needs to be rebooted. There is no logging info from adb, so I am at a loss on how to debug it.

If you have any idea why this might be, or how I can collect more debug info, please let me know.
Thanks,

Frank

andreaskeller commented 8 years ago

@frankliu81 you could try and use branch version-2 which is a rewrite to not use dm77/barcodescanner anymore as with a project of mine there was an error in a part of the library which I could not fix easily. You can include the following in your package.json:

"react-native-barcodescanner": "git+https://github.com/ideacreation/react-native-barcodescanner/#version-2", hope that helps.

jrm2k6 commented 8 years ago

@andreaskeller What was the error that you couldn't fix easily? My issue right now is that I have my first screen using the Camera. and when I navigate to the second screen, I can see this in my adb log (app crashes):

java.lang.RuntimeException: Camera is being used after Camera.release() was called
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at android.hardware.Camera.native_getParameters(Native Method)
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at android.hardware.Camera.getParameters(Camera.java:1890)
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at me.dm7.barcodescanner.zxing.ZXingScannerView.onPreviewFrame(ZXingScannerView.java:88)
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1110)
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:148)
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:5417)
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
06-02 14:17:16.124  2056  2056 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-02 14:17:16.129   635   647 W ActivityManager:   Force finishing activity com.inventology/.MainActivity
frankliu81 commented 8 years ago

@andreaskeller, I updated my package.json with "react-native-barcodescanner": "git+https://github.com/ideacreation/react-native-barcodescanner/#version-2",

I did npm install, and that was successful When I did react-native run-android, this is the build error I got: :app:compileDebugJavaWithJavac /Users/frankliu/codecore/react_native/AwesomeFootprintsRN/android/app/src/main/java/com/awesomefootprints/MainActivity.java:10: error: cannot find symbol import com.eguma.barcodescanner.BarcodeScanner;                                ^   symbol:   class BarcodeScanner   location: package com.eguma.barcodescanner /Users/frankliu/codecore/react_native/AwesomeFootprintsRN/android/app/src/main/java/com/awesomefootprints/MainActivity.java:40: error: cannot find symbol             new BarcodeScanner()                 ^   symbol:   class BarcodeScanner   location: class MainActivity 2 errors :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

BUILD FAILED

jrm2k6 commented 8 years ago

@frankliu81 it should be import com.eguma.barcodescanner.BarcodeScannerPackage; and new BarcodeScannerPackage

frankliu81 commented 8 years ago

@jrm2k6 Thanks. I made those updates for "import com.eguma.barcodescanner.BarcodeScannerPackage; and new BarcodeScannerPackage", and now I am getting a "Super expression must either be null or a function, not undefined error" The red screen callstack points to line 10 of BarcodeScanner.js, which is "import Viewfinder from './Viewfinder';" And if I put a console.log(Component); right after the import statement in Viewfinder.js, it shows it is undefined. Any ideas?

I npm install to the latest react and react-native today, and I was getting a weird ReactPerf().injection.injectMeasure error, https://github.com/jhabdas/react-native-webpack-starter-kit/issues/101. So I actually revert back to "react": "15.0.2", "react-native": "0.26.1", not sure if that makes any difference.

By the way, I am a bit new to ReactNative, how were you able to get the stack trace in your adb log when your app crashes. I run adb logcat *:S ReactNative:V ReactNativeJS:V. When my app crashes, I don't see any callstack at all. And with a simple navigator component, the app also is super slow whenever I try to do debug JS remotely.

jrm2k6 commented 8 years ago

@frankliu81 For adb I just run adb logcat com.appname/.MainActivity

I don't have any issue with this package, at least when it comes to using the component so I can't really help you when it comes to your exception. Maybe restarting the package/ rm-rfed node_modules && npm install could help.

frankliu81 commented 8 years ago

@jrm2k6, @andreaskeller, in order to use "react-native-barcodescanner": "git+https://github.com/ideacreation/react-native-barcodescanner/#version-2", I had to change the top of react-native-barcodescaner's ViewFinder.js to workaround Component being undefined, and the "Super expression must either be null or a function, not undefined error" (I compared with my own project when I react-native init): import React, { Component, PropTypes } from 'react'; //import React, { import { ActivityIndicatorIOS, //Component, Platform, ProgressBarAndroid, //PropTypes, StyleSheet, View, } from 'react-native';

My react version is 15.0.2, react-native is 0.26.1.

While the scanner is up, I still crashed my Nexus 4 phone with Android 5, four or five times while the scanner is up in 15 minutes. The only thing beside scanning that I did was Reloading the JS from the developer menu. I am also not seeing the console.log from the example when the barcode is read with this branch, I am not sure why so I will have to continue to prototype with "react-native-barcodescanner": "^2.0.0" for now.

andreaskeller commented 8 years ago

@jrm2k6 thanks for helping out! I'm not exactly sure anymore what error I couldn't fix but it was something similar, because it crashed in the method me.dm7.barcodescanner.zxing.ZXingScannerView.onPreviewFrame.

@frankliu81 I merged the version-2 branch into master and published a new version 3.0.0 to npm where the import statements of ViewFinder.js are fixed. After reloading the js the camera didn't start again, because the camera wasn't stopped properly and this caused a black screen for me as well. With the new version this should be fixed too. Could you test the new version and report back if you still encounter any issues? Thank you.

frankliu81 commented 8 years ago

@andreaskeller Thanks for the update. I plan to try out the new version, but maybe after next week. I am building a simple prototype for a demo by next week, and version 2.0 with its occasional crashes is still usable. Yesterday, just looking at the ViewFinder.js error was taking away some time.

jqn commented 7 years ago

@andreaskeller - I kept running into the same issue @frankliu81. In my case the app would crash every time the second time the barcode scanner was invoked. I tried your latest update and for now everything seems to be working well. My test device is a Samsung Galaxy s6 edge with Android 6.01