jamesisaac / react-native-background-task

Periodic background tasks for React Native apps, cross-platform (iOS and Android), which run even when the app is closed.
MIT License
1.1k stars 110 forks source link

Always crashes app when job starts #28

Open jarodhanko opened 6 years ago

jarodhanko commented 6 years ago

I am defining my background task so that it is not doing anything, simply running, and then finishing. The task schedules just fine, and adb says the job is running, however my app immediately crashes ('Appname' has stopped). I double checked based off of the other issues and the manual configuration is correct. I am running an Expokit project, where the only linked libraries are react-native-background-task and realm (for react-native-queue). I haven't been able to get any actual error information (adb doesn't show any errors, and I can't run the Android debugger at the same time as expo). Any ideas on what the issue might be?

Using Galaxy S8+ running 7.0.0 (same issue on GS4 running 5.0.1)

Example adb logs

02-27 09:55:33.844 28582 28582 D BackgroundTask: Setting foreground false
02-27 09:55:33.844 28582 28582 D BackgroundTask: Committing job schedule
02-27 10:04:00.142 28582 29554 D BackgroundTask: Job is running
02-27 10:04:00.166 28582 28582 D BackgroundTask: Returning HeadlessJsTaskConfig, timeout=30 ms
02-27 10:04:33.210 29702 29805 D BackgroundTask: Job is running
02-27 10:04:33.268 29702 29702 D BackgroundTask: Returning HeadlessJsTaskConfig, timeout=30 ms
02-27 10:06:12.750 29966 30016 D BackgroundTask: Job is running
02-27 10:06:12.832 29966 29966 D BackgroundTask: Returning HeadlessJsTaskConfig, timeout=30 ms
02-27 10:08:33.252 30304 30352 D BackgroundTask: Job is running
02-27 10:08:33.339 30304 30304 D BackgroundTask: Returning HeadlessJsTaskConfig, timeout=30 ms
02-27 10:08:46.141 30363 30363 D BackgroundTask: Returning HeadlessJsTaskConfig, timeout=30 ms

Defining Background task in root App.js outside of component as

BackgroundTask.define(() => {
    //tried adding console.log("words") but it doesn't seem to get that far
    BackgroundTask.finish()
});
jarodhanko commented 6 years ago

I think it might be related to this expo issue

Edit: That did seem to be this issue. It is now running but lists Module AppRegistry is not a registered callable module

02-27 12:51:38.316 30638  2659 D BackgroundTask: Job is running
02-27 12:51:38.378 30638 30638 D BackgroundTask: Returning HeadlessJsTaskConfig, timeout=30 ms
02-27 12:51:38.386 30638 30638 D ReactNative: ReactInstanceManager.ctor()
02-27 12:51:38.466 30638 30638 D ReactNative: ReactInstanceManager.createReactContextInBackground()
02-27 12:51:38.471 30638 30638 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
02-27 12:51:39.446 30638 30638 D ReactNative: ReactInstanceManager.onJSBundleLoadedFromServer()
02-27 12:51:39.448 30638 30638 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
02-27 12:51:39.448 30638 30638 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
02-27 12:51:39.455 30638  2680 D ReactNative: ReactInstanceManager.createReactContext()
02-27 12:51:39.466 30638  2680 D ReactNative: Initializing React Xplat Bridge.
02-27 12:51:39.472 30638  2680 D ReactNative: Initializing React Xplat Bridge before initializeBridge
02-27 12:51:39.515 30638  2680 D ReactNative: Initializing React Xplat Bridge after initializeBridge
02-27 12:51:39.515 30638  2680 D ReactNative: CatalystInstanceImpl.runJSBundle()
02-27 12:51:39.521 30638  2682 D ReactNative: ReactInstanceManager.setupReactContext()
02-27 12:51:39.521 30638  2682 D ReactNative: CatalystInstanceImpl.initialize()
02-27 12:51:40.136 30638  2681 E ReactNativeJS: The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.
02-27 12:51:40.157 30638  2681 E ReactNativeJS: Module AppRegistry is not a registered callable module (calling startHeadlessTask)
jarodhanko commented 6 years ago

This issue should probably be closed, since it appears that react-native-background-task (and react-native-background-job) or any other library that requires access to the application context is not supported in Expokit (afaict). If anyone knows of a way to make it work, please let me know.