React-native-background-geolocation: Inclusion of library in android react native project causes force close

Created on 2 May 2018  路  13Comments  路  Source: mauron85/react-native-background-geolocation

Hi,
Great library, we have successfully implemented this on iOS but on Android we are experiencing force closes. The error seems to come from com.marianhello.bgloc.Config.writeToParcel

Your Environment

  • Plugin version: Latest (from npm)
  • Platform: Android
  • OS version: 6.0.1
  • Device manufacturer and model: Moto G
  • React Native version: 0.49
  • Plugin configuration options:
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
      stationaryRadius: 50,
      distanceFilter: 50,
      notificationTitle: 'Background tracking',
      notificationText: 'enabled',
      debug: true,
      startOnBoot: false,
      stopOnTerminate: false,
      locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
      interval: 10000,
      fastestInterval: 5000,
      activitiesInterval: 10000,
      stopOnStillActivity: false,
      url: 'our url',
      httpHeaders: {
        'X-FOO': 'bar'
      },
      // customize post properties
      postTemplate: {
        lat: '@latitude',
        lon: '@longitude',
      }

Context


When we include your library in our android project, the app force closes and becomes unusable.

Expected Behavior


The app should load, wait for the user activity, authorise location permissions through OS prompt, begin tracking.

Actual Behavior


It force closes on launch.

Context


Preventing core functionality in our app. Trying to track users in background.

Debug logs

https://pastebin.com/MgRgr0me

bug

All 13 comments

What is the version of plugin and config options?

Updated question with config :)

I don't see anything what could cause config to throw IOException writing serializable object (name = com.marianhello.bgloc.data.HashMapLocationTemplate) as I found in your log. Are you sure you don't use some fancy object in postTemplate?

What is the output of BackgroundGeolocation.getConfig(c=>console.log(c)); before you call BackgroundGeolocation.start()

Will check ASAP. The way we implemented the js side was in a helper component in our top level app structure. I don鈥檛 think the js was even being executed before the force close - I suspect the issue is on the initialisation of the native module. I鈥檒l try and do some more digging for tomorrow. It鈥檚 for an important project though so we have managed to mitigate this using a background task runner to call the navigator getcurrentposition method at an interval. We would love to be able to implement your solution though!

If I鈥檓 able to I will be happy to propose a fix by way of PR.

Ok I can reproduce your issue with:

      postTemplate: {
        lat: '@latitude',
        lon: '@longitude',
        crash: {
          a: 'a',
          b: 'b'
        }
      }

As stated in documentation object values are not supported only strings. However this should not crash app, so will take look onto it.

Fixed in alpha.25. Now plugin throws js error when non string keys detected

EDIT: so configuration errors can be trapped early in development process (famous react-native red error screen).

Awesome, thank you, will pick this up again today and see if we can get it working our end. Thanks for the speedy fix!

You're welcome. Keep in mind that this fix, that will probably throw error in your case. :) But from react's red error screen you should be able to determine what config props is wrong.

That's fine, thanks, looks like we will configure a new endpoint on our API to accept the flattened object - or is there a way to specify a function that handles the API calls ourselves?

Well you can also rewrite plugin to be able to read object values. Such a contribution will be welcome.

Will have a look into this when I get some free time :)

@antwan2093 latest alpha.26 kind of support nested objects and arrays, ~but first level only~:

Eg. this will work:

BackgroundGeolocation.configure({
  postTemplate: {
    arr: ['123', 'abc'],
    complex: {
      foo: 'bar'
    }
  }
});

~However second level another Object will be serialized as [Object].~

EDIT: It should be working to any level. I did stupid in mistake on server side printing with console.log only, instead of JSON.stringify!

Was this page helpful?
0 / 5 - 0 ratings