react-native-beacons-manager
react-native-beacons-manager copied to clipboard
Crash on launch with 1.1.0 (master)
First of all, thank you for this plugin !
The current master branch (5f0d44e850e607bd2629476bbf701beec3c4d093
) crashes on Android. I think it is because the beaconServiceConnected
event is sent too early.
A quick and dirty fix is to comment the line:
sendEvent(mReactContext, "beaconServiceConnected", null);
in BeaconsAndroidModule.java
Version
1.1.0
Platform
Android
OS version
android 6.0
Steps to reproduce
- Launch demo App on Android. Sometimes it takes several launches to crash
11-21 17:39:58.957 22955 22955 V BeaconsAndroidModule: onBeaconServiceConnect
11-21 17:39:58.957 22955 22955 D AndroidRuntime: Shutting down VM
11-21 17:39:58.957 22955 23790 D ReactNative: Initializing React Xplat Bridge after initializeBridge
11-21 17:39:58.957 22955 23790 D ReactNative: CatalystInstanceImpl.runJSBundle()
11-21 17:39:58.957 22955 22955 E AndroidRuntime: FATAL EXCEPTION: main
11-21 17:39:58.957 22955 22955 E AndroidRuntime: Process: com.demo, PID: 22955
11-21 17:39:58.957 22955 22955 E AndroidRuntime: java.lang.RuntimeException: Tried to access a JS module before the React instance was fully set up. Calls to ReactContext#getJSModule should only happen once initialize() has been called on your native module.
11-21 17:39:58.957 22955 22955 E AndroidRuntime: at com.facebook.react.bridge.ReactContext.getJSModule(ReactContext.java:105)
11-21 17:39:58.957 22955 22955 E AndroidRuntime: at com.mackentoch.beaconsandroid.BeaconsAndroidModule.sendEvent(BeaconsAndroidModule.java:404)
11-21 17:39:58.957 22955 22955 E AndroidRuntime: at com.mackentoch.beaconsandroid.BeaconsAndroidModule.onBeaconServiceConnect(BeaconsAndroidModule.java:243)
11-21 17:39:58.957 22955 22955 E AndroidRuntime: at org.altbeacon.beacon.BeaconManager$BeaconServiceConnection.onServiceConnected(BeaconManager.java:933)
Hi, just FYI I am also seeing this issue.
Hi,
This issue can be avoided by adding this to 'node_modules/react-native-beacons-manager/com/mackentoch/beaconsandroid/BeaconsAndroidModule.java':
if (reactContext.hasActiveCatalystInstance()) { <---- add this
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
} <---- and this
Hi, Could you provide me with an example of how you solved this problem?
Hi @brayanAP, I did what @mojotti wrote and it works.
Go to: node_modules/react-native-beacons-manager/android/src/main/java/com/mackentoch/beaconsandroid/BeaconsAndroidModule.java'
Then change this method from this (line 404 for me):
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
to this:
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
if (reactContext.hasActiveCatalystInstance()) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
}
Restart app and it should work ;)