[expo-background-fetch] App has stopped when is killed and background task try to execute
See original GitHub issue🐛 Bug Report
Summary of Issue
I’m having the AppName has stopped alert when use expo-background-fetch
AND I have Proguard enabled.
The issue is similar but not is the same that was reported. All works great if Proguard is disabled, but when I enable Proguard the app crash in background.
This happen in Bare workflow, I’m not tested in Managed workflow. Only Android.
Related Issues
Another related issues to background-location
, but I have this with expo-background-fetch
and only when Proguard is enabled.
- https://github.com/expo/expo/issues/9570
- https://github.com/expo/expo/issues/9288
- https://github.com/expo/expo/issues/8483
Logcat
2020-09-30 07:53:43.632 5371-5371/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx, PID: 5371
java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke interface method 'void l.b.a.b.a(android.content.Context, l.b.a.b$b, java.lang.Runnable, l.b.b.l.e)' on a null object reference
at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:112)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void l.b.a.b.a(android.content.Context, l.b.a.b$b, java.lang.Runnable, l.b.b.l.e)' on a null object reference
at expo.modules.taskManager.h.a(Unknown Source:125)
at expo.modules.taskManager.c.a(Unknown Source:2)
at expo.modules.backgroundfetch.BackgroundFetchTaskConsumer.didExecuteJob(Unknown Source:8)
at expo.modules.taskManager.h.b(Unknown Source:64)
at expo.modules.taskManager.TaskJobService.onStartJob(Unknown Source:9)
at android.app.job.JobService$1.onStartJob(JobService.java:71)
at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:108)
Environment - output of expo diagnostics
& the platform(s) you’re targeting
Expo CLI 3.27.12 environment info:
System:
OS: macOS 10.15.5
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.4.0 - /usr/local/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.14.5 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
Android SDK:
Android NDK: 21.3.6528147
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6514223
Xcode: 12.0/12A7209 - /usr/bin/xcodebuild
npmPackages:
expo: ~39.0.3 => 39.0.3
react: 16.13.1 => 16.13.1
react-native: ~0.63.3 => 0.63.3
npmGlobalPackages:
expo-cli: 3.27.12
Expo Workflow: bare
expo-background-fetch: 8.5.0
expo-task-manager: 8.5.0
Reproducible Demo
Steps to Reproduce
- Create a Bare project
- Install
expo-background-fetch
- Create a task to run in background
- Open Android Studio and enable Proguard (
def enableProguardInReleaseBuilds = true
) - Create a release sdk
- Install in your device, open the app and kill the app.
- Wait a few minutes to see the AppName has stopped
Expected Behavior vs Actual Behavior
Expected Behavior: background tasks works great Actual Behavior: Error AppName has stopped
I tested with the following proguard rule but doesn’t work.
-keep class expo.modules.taskManager { *; }
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Expo : Background and Closed Application - Stack Overflow
To run a function in background in Expo is TaskManager , but work only if app is in FOREGROUND. How to run a...
Read more >Expo TaskManager crash when killing app. : r/reactnative
Expo TaskManager crash when killing app. I am running a background task to track locations with Location.startLocationUpdatesAsync().
Read more >react-native-background-fetch - npm
Background Fetch is a very simple plugin which attempts to awaken an app in the background about every 15 minutes, providing a short...
Read more >How to handle Background App Refresh with HealthKit in ...
Triggering background fetch event while app is running is not enough. In practice our apps should be wake up from terminated state due...
Read more >iOS background processing - Background App Refresh Task
Performance: ensure background execution does not have any negative effect on active usage. Privacy: Users should be aware of background tasks ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @byCedric, I created a reproducible demo: https://github.com/RodolfoGS/expo-background-fetch-isseu10475
How to reproduce.
How I created this demo:
expo init TestBackgroundFetch
cd TestBackgroundFetch
expo install expo-background-fetch
expo install expo-task-manager
App.js
:def enableProguardInReleaseBuilds = true
proguard-rules.pro
file to fix another bug that are described belowAdditional to this, I found another bug when you run
BackgroundFetch.registerTaskAsync
.I fixed this bug adding this rule to proguard rules file https://github.com/RodolfoGS/expo-background-fetch-isseu10475/blob/master/android/app/proguard-rules.pro#L12
Tested on Android Nexus 6P - Android 8.1.0
@byCedric, I don’t think that my PR fixed this bug. However, we now can add
DoNotStrip
annotation toBackgrondFetchTaskConsumer
… and this should fix the problem withBackgroundFetch.registerTaskAsync
.Unfortunately, it won’t fix the problem with the
AppName has stopped
alert.Frankly speaking, I really don’t understand why the
BackgrondFetchTaskConsumer
is dropped here 🤷🏼♂️ I’m not familiar with the task manager code.