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 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:closed
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Arykcommented, Aug 24, 2020

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

2reactions
mbrettercommented, Jul 27, 2020

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:

  • start your app as usual from the dev env
  • send the app into the background, until the background task runs, everything is working so far
  • terminate the app and expo, the background task still runs, but expo crashes:
07-27 14:49:00.030 25501 25501 E Expo    : Cannot initialize app loader. host.exp.exponent.taskManager.ExpoHeadlessAppLoader
07-27 14:49:00.030 25501 25501 W System.err: java.lang.ClassNotFoundException: host.exp.exponent.taskManager.ExpoHeadlessAppLoader
07-27 14:49:00.030 25501 25501 W System.err: 	at java.lang.Class.classForName(Native Method)
07-27 14:49:00.031 25501 25501 W System.err: 	at java.lang.Class.forName(Class.java:453)
07-27 14:49:00.031 25501 25501 W System.err: 	at java.lang.Class.forName(Class.java:378)
07-27 14:49:00.031 25501 25501 W System.err: 	at l.d.a.b.a(AppLoaderProvider.java:2)
07-27 14:49:00.031 25501 25501 W System.err: 	at l.d.a.b.b(AppLoaderProvider.java:2)
07-27 14:49:00.031 25501 25501 W System.err: 	at expo.modules.taskManager.TaskService.getAppLoader(TaskService.java:2)
07-27 14:49:00.031 25501 25501 W System.err: 	at expo.modules.taskManager.TaskService.executeTask(TaskService.java:17)
07-27 14:49:00.031 25501 25501 W System.err: 	at expo.modules.taskManager.Task.execute(Task.java:2)
07-27 14:49:00.031 25501 25555 W com.amplitude.api.DeviceInfo: Google Play Services not available
07-27 14:49:00.031 25501 25501 W System.err: 	at abi38_0_0.expo.modules.backgroundfetch.BackgroundFetchTaskConsumer.didExecuteJob(BackgroundFetchTaskConsumer.java:1)
07-27 14:49:00.031 25501 25501 W System.err: 	at expo.modules.taskManager.TaskService.handleJob(TaskService.java:7)
07-27 14:49:00.031 25501 25501 W System.err: 	at expo.modules.taskManager.TaskJobService.onStartJob(TaskJobService.java:3)
07-27 14:49:00.031 25501 25501 W System.err: 	at android.app.job.JobService$1.onStartJob(JobService.java:62)
07-27 14:49:00.031 25501 25501 W System.err: 	at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:108)
07-27 14:49:00.031 25501 25501 W System.err: 	at android.os.Handler.dispatchMessage(Handler.java:106)
07-27 14:49:00.031 25501 25501 W System.err: 	at android.os.Looper.loop(Looper.java:280)
07-27 14:49:00.031 25501 25501 W System.err: 	at android.app.ActivityThread.main(ActivityThread.java:6706)
07-27 14:49:00.031 25501 25501 W System.err: 	at java.lang.reflect.Method.invoke(Native Method)
07-27 14:49:00.031 25501 25501 W System.err: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
07-27 14:49:00.031 25501 25501 W System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
07-27 14:49:00.031 25501 25501 W System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "host.exp.exponent.taskManager.ExpoHeadlessAppLoader" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/host.exp.exponent-n3YnG-ZfhnPSIRKhQPYKPA==/base.apk"],nativeLibraryDirectories=[/data/app/host.exp.exponent-n3YnG-ZfhnPSIRKhQPYKPA==/lib/arm64, /data/app/host.exp.exponent-n3YnG-ZfhnPSIRKhQPYKPA==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
07-27 14:49:00.031 25501 25501 W System.err: 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
07-27 14:49:00.031 25501 25501 W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    System:
      OS: Linux 4.15 Ubuntu 18.04.4 LTS (Bionic Beaver)
      Shell: 4.4.20 - /bin/bash
    Binaries:
      Node: 10.21.0 - /usr/bin/node
      Yarn: 1.22.4 - /usr/bin/yarn
      npm: 6.14.5 - /usr/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    IDEs:
      Android Studio: 4.0 AI-193.6911.18.40.6514223
    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.0.tar.gz => 0.62.2 
      react-native-web: ~0.11.7 => 0.11.7 
    npmGlobalPackages:
      expo-cli: 3.21.13


Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot initialize app loader. host.exp.exponent.taskManager ...
This only occurs when the standalone .apk app is in a terminated state on Android (it works in the foreground and background). Are...
Read more >
Built Expo app crashes on start up: Didn't find class "host.exp ...
Solved! Turns out that the error message had nothing to do with the crash. I had misplaced the API key. Moving it from...
Read more >
Background Work Overview | Android Developers
This guide explains what qualifies as background work, defines background task categories, provides you with criteria to categorize your tasks, ...
Read more >
Schedule tasks with WorkManager Part of Android Jetpack.
Work is persistent when it remains scheduled through app restarts and system reboots. Because most background processing is best accomplished ...
Read more >
Background optimization | Android Developers
Background processes can be memory- and battery-intensive. ... This can have a substantial impact on both device performance and user experience.
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