When testing the terminated-state location tracking portion of my app on an Android emulator, I get the following error message:
08-08 17:49:32.480 22495 22495 E Expo : Cannot initialize app loader. host.exp.exponent.taskManager.ExpoHeadlessAppLoader
08-08 17:49:32.480 22495 22495 W System.err: java.lang.ClassNotFoundException: host.exp.exponent.taskManager.ExpoHeadlessAppLoader
08-08 17:49:32.480 22495 22495 W System.err: at java.lang.Class.classForName(Native Method)
08-08 17:49:32.480 22495 22495 W System.err: at java.lang.Class.forName(Class.java:454)
08-08 17:49:32.480 22495 22495 W System.err: at java.lang.Class.forName(Class.java:379)
08-08 17:49:32.480 22495 22495 W System.err: at l.d.a.b.a(AppLoaderProvider.java:2)
08-08 17:49:32.480 22495 22495 W System.err: at l.d.a.b.b(AppLoaderProvider.java:2)
08-08 17:49:32.480 22495 22495 W System.err: at expo.modules.taskManager.TaskService.getAppLoader(TaskService.java:2)
08-08 17:49:32.480 22495 22495 W System.err: at expo.modules.taskManager.TaskService.executeTask(TaskService.java:17)
08-08 17:49:32.480 22495 22495 W System.err: at expo.modules.taskManager.Task.execute(Task.java:2)
08-08 17:49:32.480 22495 22495 W System.err: at expo.modules.location.taskConsumers.LocationTaskConsumer.executeTaskWithLocationBundles(LocationTaskConsumer.java:4)
08-08 17:49:32.480 22495 22495 W System.err: at expo.modules.location.taskConsumers.LocationTaskConsumer.didExecuteJob(LocationTaskConsumer.java:10)
08-08 17:49:32.480 22495 22495 W System.err: at expo.modules.taskManager.TaskService.handleJob(TaskService.java:7)
08-08 17:49:32.480 22495 22495 W System.err: at expo.modules.taskManager.TaskJobService.onStartJob(TaskJobService.java:3)
08-08 17:49:32.480 22495 22495 W System.err: at android.app.job.JobService$1.onStartJob(JobService.java:62)
08-08 17:49:32.480 22495 22495 W System.err: at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:108)
08-08 17:49:32.480 22495 22495 W System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
08-08 17:49:32.480 22495 22495 W System.err: at android.os.Looper.loop(Looper.java:223)
08-08 17:49:32.480 22495 22495 W System.err: at android.app.ActivityThread.main(ActivityThread.java:7523)
08-08 17:49:32.481 22495 22495 W System.err: at java.lang.reflect.Method.invoke(Native Method)
08-08 17:49:32.481 22495 22495 W System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
08-08 17:49:32.481 22495 22495 W System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
08-08 17:49:32.481 22495 22495 W System.err: Caused by: java.lang.ClassNotFoundException: host.exp.exponent.taskManager.ExpoHeadlessAppLoader
This only occurs when the standalone .apk app is in a terminated state on Android (it works in the foreground and background).
Are there other Expo versions that do not generate this error on Android that I should downgrade to, or am I making a mistake somewhere? My code works well on an iOS simulator and a physical iOS device.
Any help would be greatly appreciated. If needed, I could provide my code or additional error logs. Thanks!
Could this be related to me having insufficient permissions to run my app in headless mode? Do I need to include more permissions from app.json / app.config.js - Expo Documentation in my app.json?
Same error I get, working well while testing but when I generate apk it gets crashed and when debugged that apk through android studio got the same error. Any solution got stuck while releasing it to production ?
I also experienced this issue. After some trial/error, I was able to get my android build working by removing import { SplashScreen } from 'expo'.
SplashScreen is now exported from expo-splash-screen (here’s the docs for it), but I was still using the export from 'expo'. After removing that, my .apk started to work again.
Here’s how I debugged this (for anyone who wants to follow along):
After creating an .apk, then dragging/dropping it into the android emulator, it would hang on the splash screen indefinitely (my project works on android and ios in development, and ios as a build, but not android as a build).
When I opened my .apk on the android emulator, I used adb logcat -v time in the terminal to print the emulator’s logs, and found this error:
I spent some time upgrading my app with expo upgrade, but that did not help. Eventually, I saw some warnings coming from SplashScreen and I decided to use expo-splash-screen instead. After making a build with that, my app began to launch. –If you create a new expo project and select the tabs option, it comes with a useCachedResources.ts hook that sets up SplashScreen.
I have exactly the same behavior, work well on expo client, but when build to apk, it crash with ClassNotFoundException ExpoHeadlessAppLoader juste after loading the splash.
Have you resolved it ? If yes, how ?