Cannot initialize app loader. host.exp.exponent.taskManager.ExpoHeadlessAppLoader

Please provide the following:

  1. SDK Version: 38
  2. Platforms(Android/iOS/web/all): Android

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!

2 Likes

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 ?

1 Like

I ended up ejecting :frowning_face:
Not the best solution, but it worked.

can you provide information on how to reproduce it? ideally a mcve?

My app also crashes with the same error message when built standalone. Works fine in the Expo client.

The crash happens immediately upon starting the app after the expo loading screen is displayed. The app just shows a generic Android activity spinner.

Creating a minimal test case would take an inordinate amount of time due to the turnaround time for expo build:android.

2020-08-27 21:14:26.021 18702-18702/? E/Expo: Cannot initialize app loader. host.exp.exponent.taskManager.ExpoHeadlessAppLoader
2020-08-27 21:14:26.021 18702-18702/? W/System.err: java.lang.ClassNotFoundException: host.exp.exponent.taskManager.ExpoHeadlessAppLoader
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at java.lang.Class.classForName(Native Method)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at java.lang.Class.forName(Class.java:454)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at java.lang.Class.forName(Class.java:379)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at l.d.a.b.a(AppLoaderProvider.java:2)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at l.d.a.b.b(AppLoaderProvider.java:2)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at expo.modules.taskManager.TaskService.getAppLoader(TaskService.java:2)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at expo.modules.taskManager.TaskService.isStartedByHeadlessLoader(TaskService.java:1)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at expo.modules.taskManager.TaskManagerInternalModule.isRunningInHeadlessMode(TaskManagerInternalModule.java:1)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at expo.modules.taskManager.TaskManagerInternalModule.onHostResume(TaskManagerInternalModule.java:1)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at org.unimodules.adapters.react.services.d$c.onHostResume(UIManagerModuleWrapper.java:2)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at com.facebook.react.bridge.ReactContext.onHostResume(ReactContext.java:5)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at com.facebook.react.ReactInstanceManager.moveToResumedLifecycleState(ReactInstanceManager.java:3)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at com.facebook.react.ReactInstanceManager.onHostResume(ReactInstanceManager.java:11)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at com.facebook.react.ReactInstanceManager.onHostResume(ReactInstanceManager.java:3)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at host.exp.exponent.k.a(RNObject.java:17)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at host.exp.exponent.k.a(RNObject.java:12)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at host.exp.exponent.k.a(RNObject.java:58)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at host.exp.exponent.experience.k.onResume(ReactNativeActivity.java:3)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at host.exp.exponent.experience.f.onResume(BaseExperienceActivity.java:1)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at host.exp.exponent.experience.ExperienceActivity.onResume(ExperienceActivity.java:1)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1453)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.app.Activity.performResume(Activity.java:7962)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4195)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.os.Handler.dispatchMessage(Handler.java:107)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.os.Looper.loop(Looper.java:214)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7356)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-08-27 21:14:26.021 18702-18702/? W/System.err: Caused by: java.lang.ClassNotFoundException: host.exp.exponent.taskManager.ExpoHeadlessAppLoader
2020-08-27 21:14:26.021 18702-18702/? W/System.err: … 35 more

Downgrading to SDK 37 did not fix the issue. I had further details in a previous post but it seems to have been collected by the spam filter.

Any update on this? I can try to provide a minimal repro if you can give me priority builds. Otherwise it will probably take days to do so.

1 Like

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:

Cannot initialize app loader. host.exp.exponent.taskManager.ExpoHeadlessAppLoader

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 ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.