react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

Android crashes when lib tries to call the RN callbacks

Open mikinw opened this issue 3 years ago • 2 comments

Your Environment

  • Plugin version: 4.4.0
  • Platform: Android
  • OS version: 9 to 12
  • Device manufacturer / model: multiple including Pixel, motorola, Galaxy
  • React Native version (react-native -v): 0.64.2
  • Plugin config
const config = {
        reset: true,
        desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
        distanceFilter: 0,
        disableElasticity: false,
        elasticityMultiplier: 1,
        stopAfterElapsedMinutes: 0,
        stopOnStationary: false,
        desiredOdometerAccuracy: 100,
        useSignificantChangesOnly: false,
        disableLocationAuthorizationAlert: true,
        locationAuthorizationRequest: 'Always',
        stationaryRadius: 25,
        locationAuthorizationAlert: {
          titleWhenNotEnabled: 'Location services are not enabled',
          titleWhenOff: 'Location services are off',
          instructions: `xxx`,
          cancelButton: 'Cancel',
          settingsButton: 'Settings'
        },
        showsBackgroundLocationIndicator: true,
        locationUpdateInterval: 5000,
        fastestLocationUpdateInterval: 10000,
        deferTime: 0,
        allowIdenticalLocations: true,
        stopTimeout: 15,
        stopDetectionDelay: 0,
        disableStopDetection: false,
        disableMotionActivityUpdates: false,
        activityType: BackgroundGeolocation.ACTIVITY_TYPE_AUTOMOTIVE_NAVIGATION,
        stopOnTerminate: false,
        startOnBoot: false,
        heartbeatInterval: 60,
        schedule: undefined,
        preventSuspend: true,
        foregroundService: true,
        enableHeadless: true,
        notification: { title: 'xxx', text: 'xxx.' },
        geofenceInitialTriggerEntry: true,
        geofenceModeHighAccuracy: false,
        debug: false,
        logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
        logMaxDays: 3
      }
      
await BackgroundGeolocation.ready(config)

Expected Behavior

The app should run

Actual Behavior

The app crashes on the users' devices

Steps to Reproduce

Unfortunately we don't collect any such data to Crashlytics

Context

The app tries to continuously monitor the location of the user (when the function is turned on) to show certain messages when relevant. There are 5, seemingly different crashes, but they only differ in the callback function being called.

Debug logs

Logs
Fatal Exception: java.lang.IllegalStateException: 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.
       at com.facebook.react.bridge.ReactContext.getJSModule(ReactContext.java:147)
       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.sendEvent(RNBackgroundGeolocationModule.java:1047)
       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.access$1400(RNBackgroundGeolocationModule.java:69)
       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule$LocationCallback.onLocation(RNBackgroundGeolocationModule.java:152)
       at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$e0.run(:31)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:6694)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


Fatal Exception: java.lang.IllegalStateException: 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.
       at com.facebook.react.bridge.ReactContext.getJSModule(ReactContext.java:147)
       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.sendEvent(RNBackgroundGeolocationModule.java:1047)
       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.access$1400(RNBackgroundGeolocationModule.java:69)
       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule$HeartbeatCallback.onHeartbeat(RNBackgroundGeolocationModule.java:271)
       at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$j0.run(:31)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:201)
       at android.app.ActivityThread.main(ActivityThread.java:6823)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)


Fatal Exception: java.lang.IllegalStateException: 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.
       at com.facebook.react.bridge.ReactContext.getJSModule(ReactContext.java:147)
       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.sendEvent(RNBackgroundGeolocationModule.java:1047)
       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.access$1400(RNBackgroundGeolocationModule.java:69)
       at com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule$ActivityChangeCallback.onActivityChange(RNBackgroundGeolocationModule.java:187)
       at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$d0.run(:36)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:201)
       at android.os.Looper.loop(Looper.java:288)
       at android.app.ActivityThread.main(ActivityThread.java:7842)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

mikinw avatar Feb 28 '22 18:02 mikinw

It seems, the crash is related to "Force stop"-ing the app from the App Info dialog.

mikinw avatar Mar 02 '22 16:03 mikinw

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] avatar May 01 '22 17:05 stale[bot]