question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android app is crashing (in background) when headlessJS job is fired in release variant

See original GitHub issue

Your Environment

  • Plugin version: 2.6.0
  • Platform: Android
  • OS version: 8.0.0
  • Device manufacturer / model: Samsung Galaxy S7
  • React Native version: 0.59.8
  • Plugin config

minimumFetchInterval: 15, stopOnTerminate: false, startOnBoot: true, enableHeadless: true,

Expected Behavior

Android app shouldn’t crash whenever Headless JS Task is fired.

Actual Behavior

Android app is crashing in release build whenever Headless JS Task is fired.

Steps to Reproduce

  1. Configure bgfetch
  2. Instal release variant of android app
  3. Run adb shell cmd jobscheduler run -f com.xxx 999
  4. App is crashing

Code

componentDidMount() {
  setUpBackgroundTask()
  BackgroundFetch.registerHeadlessTask(setUpBackgroundTask)
}

const setUpBackgroundTask = () => {
  BackgroundFetch.configure(
    {
      minimumFetchInterval: 15,
      stopOnTerminate: false,
      startOnBoot: true,
      enableHeadless: true,
    },
    () => {
      _checkTerminatingAndTerminate()
    }
  )
  BackgroundFetch.status(status => {
    switch (status) {
      case BackgroundFetch.STATUS_RESTRICTED:
        showAlertMessage(
          determineErrorMessage(
            {
              response: {
                err_code: "ERROR_BACKGROUND_APP_REFRESH_RESTRICTED",
              },
            },
            () => {
              store.dispatch(setDrivingModeOff())
            }
          )
        )
        break
      case BackgroundFetch.STATUS_DENIED:
        showAlertMessage(
          determineErrorMessage(
            {
              response: {
                err_code: "ERROR_BACKGROUND_APP_REFRESH_DENIED",
              },
            },
            () => {
              store.dispatch(setDrivingModeOff())
            }
          )
        )
        break
    }
  })
}

Debug logs

07-23 14:03:00.277  5812  5812 D TSBackgroundFetch: HeadlessJobService onStartJob
07-23 14:03:00.351  5812  5812 D ReactNative: ReactInstanceManager.createReactContextInBackground()
07-23 14:03:00.351  5812  5812 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
07-23 14:03:00.351  5812  5812 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundFromBundleLoader()
07-23 14:03:00.351  5812  5812 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
07-23 14:03:00.351  5812  5812 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
07-23 14:03:00.362  5812  5834 D ReactNative: ReactInstanceManager.createReactContext()
07-23 14:03:00.441  5812  5834 D ReactNative: Initializing React Xplat Bridge.
07-23 14:03:00.446  5812  5834 D ReactNative: Initializing React Xplat Bridge before initializeBridge
07-23 14:03:00.461  5812  5834 D ReactNative: Initializing React Xplat Bridge after initializeBridge
07-23 14:03:00.461  5812  5834 D ReactNative: CatalystInstanceImpl.runJSBundle()
07-23 14:03:00.479  5812  5839 D ReactNative: ReactInstanceManager.setupReactContext()
07-23 14:03:00.479  5812  5839 D ReactNative: CatalystInstanceImpl.initialize()
07-23 14:03:00.985  5812  5812 D TSBackgroundFetch: onHeadlessJsTaskStart: 1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
christocracycommented, Jul 24, 2019

Of course.

0reactions
roryabrahamcommented, Aug 26, 2021

Thanks @christocracy!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crashes | Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >
Release app crashes instantly when run. Debug version is ...
I can run my app fine on my phone while debugging but by running npx react-native run-android --variant=release or making a release apk...
Read more >
How to Fix Crashing Apps on an iPhone or Android?
Update App To The Last Version, The App Crash Fixer. Sometimes app-crashing is not caused by your phone, but rather the app itself....
Read more >
Headless JS - React Native
Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example,...
Read more >
Troubleshooting build errors and crashes - Expo Documentation
For example, you might see something like this on your Android builds: Terminal ... Locally compile and run the Android app in release...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found