react-native-beacons-manager icon indicating copy to clipboard operation
react-native-beacons-manager copied to clipboard

Crash on launch with 1.1.0 (master)

Open EliotAndres opened this issue 6 years ago • 4 comments

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

  1. 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)

EliotAndres avatar Nov 21 '17 16:11 EliotAndres

Hi, just FYI I am also seeing this issue.

ashemah avatar Dec 05 '17 00:12 ashemah

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

mojotti avatar Dec 22 '17 08:12 mojotti

Hi, Could you provide me with an example of how you solved this problem?

brayanAP avatar Jan 15 '19 00:01 brayanAP

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 ;)

Pacn91 avatar Jan 22 '19 15:01 Pacn91