Android Dev Client Unstable when using Background Tasks: ClassNotFoundException: host.exp.exponent.taskManager.ExpoHeadlessAppLoader
See original GitHub issue🐛 Bug Report
Summary of Issue
The Android Expo client gets unstable when using background tasks. From the first time a client app with background tasks is started inside the client, the client gets unstable and crashes on start (even before getting to the app selector screen). Aparrently, sometimes it can get to the app selector and selection of an app is possible. After that, the app runs stable until the next restart.
The adb log on a crash looks this:
07-27 09:15:53.816 6576 6657 E Expo : Cannot initialize app loader. host.exp.exponent.taskManager.ExpoHeadlessAppLoader
07-27 09:15:53.816 6576 6657 W System.err: java.lang.ClassNotFoundException: host.exp.exponent.taskManager.ExpoHeadlessAppLoader
07-27 09:15:53.816 6576 6657 W System.err: at java.lang.Class.classForName(Native Method)
07-27 09:15:53.816 6576 6657 W System.err: at java.lang.Class.forName(Class.java:454)
07-27 09:15:53.816 6576 6657 W System.err: at java.lang.Class.forName(Class.java:379)
[...]
As the app can be started after multiple tries and runs stable after that, I assume this is some kind of race condition. Note: the crash appears before getting to the app selector screen, so I guess it is not an issue with the client app(s).
Also, the issue does not appear in a built standalone app, only in the Expo client. The client is nearly unusable due to this issue.
Environment - output of expo diagnostics
& the platform(s) you’re targeting
Expo CLI 3.22.1 environment info:
System:
OS: Linux 5.6 Fedora 32 (Workstation Edition) 32 (Workstation Edition)
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 14.5.0 - ~/.nvm/versions/node/v14.5.0/bin/node
Yarn: 1.22.4 - ~/.nvm/versions/node/v14.5.0/bin/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v14.5.0/bin/npm
npmPackages:
expo: ^38.0.8 => 38.0.8
react: ~16.11.0 => 16.11.0
react-dom: ~16.11.0 => 16.11.0
react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2
react-native-web: ~0.11.7 => 0.11.7
npmGlobalPackages:
expo-cli: 3.22.1
Android device is a OnePlus 6, Android 10, Expo client version 2.16.1.
Reproducible Demo
Steps to Reproduce
Create an app with a background task. The background task pulls in Location info. Run it in the Android client.
Expected Behavior vs Actual Behavior
Expected: run the app without issue and stable on reloads. Actual: Expo client is crashing on startup, crashing on client app startup, crashing at app reload. It is crashing all over the place.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (1 by maintainers)
They say this issue is fixed in SDK 39 but I haven’t seen anyone verify it. Can someone from Expo comment on this issue…it’s pretty severe.
Made a forum posting trying to get some clarity on where this is at:
https://forums.expo.io/t/startlocationupdatesasync-crashes-app-on-sdk-38-android-managed/42035
I can confirm this, I’m not using the
Location.startLocationUpdatesAsync()
, our app just reads and writes from Async storage using the background-fetch module. I can reproduce it by following these steps: