App .apk build crashes on first load then works after reopening the app.

Hello :wave: there

What’s happening?
The App .apk build crashes on first load then works after reopening the app, this behaviour happens on both emulator and physical devices.

The app works fine on the expo go app for both android and ios.

Log cat error

6765-6824/com.company.appname E/ReactNativeJS: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
          This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
2022-05-24 12:08:09.997 6765-6825/com.company.appname E/unknown:ReactContextBaseJavaModule: Unhandled SoftException
    java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by DeviceInfo
        at com.facebook.react.bridge.ReactContextBaseJavaModule.getReactApplicationContextIfActiveOrWarn(ReactContextBaseJavaModule.java:66)
        at com.facebook.react.modules.deviceinfo.DeviceInfoModule.invalidate(DeviceInfoModule.java:114)
        at com.facebook.react.bridge.ModuleHolder.destroy(ModuleHolder.java:110)
        at com.facebook.react.bridge.NativeModuleRegistry.notifyJSInstanceDestroy(NativeModuleRegistry.java:108)
        at com.facebook.react.bridge.CatalystInstanceImpl$1.run(CatalystInstanceImpl.java:368)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:223)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
        at java.lang.Thread.run(Thread.java:923)
2022-05-24 12:08:09.997 6765-6825/com.company.appname E/unknown:ReactContextBaseJavaModule: Unhandled SoftException
    java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by AppState
        at com.facebook.react.bridge.ReactContextBaseJavaModule.getReactApplicationContextIfActiveOrWarn(ReactContextBaseJavaModule.java:66)
        at com.facebook.react.modules.appstate.AppStateModule.invalidate(AppStateModule.java:127)
        at com.facebook.react.bridge.ModuleHolder.destroy(ModuleHolder.java:110)
        at com.facebook.react.bridge.NativeModuleRegistry.notifyJSInstanceDestroy(NativeModuleRegistry.java:108)
        at com.facebook.react.bridge.CatalystInstanceImpl$1.run(CatalystInstanceImpl.java:368)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:223)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
        at java.lang.Thread.run(Thread.java:923)
2022-05-24 12:08:09.997 6765-6825/com.company.appname E/unknown:ReactContextBaseJavaModule: Unhandled SoftException
    java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by NativeAnimatedModule
        at com.facebook.react.bridge.ReactContextBaseJavaModule.getReactApplicationContextIfActiveOrWarn(ReactContextBaseJavaModule.java:66)
        at com.facebook.react.animated.NativeAnimatedModule.invalidate(NativeAnimatedModule.java:897)
        at com.facebook.react.bridge.ModuleHolder.destroy(ModuleHolder.java:110)
        at com.facebook.react.bridge.NativeModuleRegistry.notifyJSInstanceDestroy(NativeModuleRegistry.java:108)
        at com.facebook.react.bridge.CatalystInstanceImpl$1.run(CatalystInstanceImpl.java:368)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:223)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
        at java.lang.Thread.run(Thread.java:923)
2022-05-24 12:08:09.997 6765-6825/com.company.appname E/unknown:ReactContextBaseJavaModule: Unhandled SoftException
    java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by FrescoModule
        at com.facebook.react.bridge.ReactContextBaseJavaModule.getReactApplicationContextIfActiveOrWarn(ReactContextBaseJavaModule.java:66)
        at com.facebook.react.modules.fresco.FrescoModule.invalidate(FrescoModule.java:202)
        at com.facebook.react.bridge.ModuleHolder.destroy(ModuleHolder.java:110)
        at com.facebook.react.bridge.NativeModuleRegistry.notifyJSInstanceDestroy(NativeModuleRegistry.java:108)
        at com.facebook.react.bridge.CatalystInstanceImpl$1.run(CatalystInstanceImpl.java:368)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:223)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)

EAS CLI 0.52.0 Environment info:
System:
OS: macOS 12.0.1
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.0 -
Yarn: 1.22.15 -
npm: 8.3.1 -
Utilities:
Git: 2.35.1 -
npmPackages:
expo: ~45.0.0 => 45.0.4
expo-updates: ~0.13.1 => 0.13.1
react: 17.0.2 => 17.0.2
react-dom: 17.0.2 => 17.0.2
react-native: 0.68.2 => 0.68.2
react-native-web: 0.17.7 => 0.17.7
npmGlobalPackages:
eas-cli: 0.52.0
expo-cli: 5.4.6
Project workflow: managed

Hi @balogun

See if running in production mode in Expo Go helps to track down the cause of this problem:

I’ve done some searching based on the errors you’re seeing and I have not found a definitive answer.
It could be that you have some JavaScript error that’s causing this, so hopefully running in production mode in Expo Go will give you more information.

Thanks for your response and suggestion @wodin

Running the in production mode ( expo start --no-dev --minify -c) via expo go app shows this error.

I am not sure which assets is being referred to here.

hmmm… I’m not sure. Is there anything mentioning assets in the logcat output?

@wodin

Here’s what I got from logcat

2022-05-25 08:22:54.198 22339-22426/host.exp.exponent E/Loader: Failed to load all assets
    java.lang.Exception: Failed to load all assets
        at expo.modules.updates.loader.Loader.handleAssetDownloadCompleted(Loader.kt:24)
        at expo.modules.updates.loader.Loader.access$handleAssetDownloadCompleted(Loader.kt:1)
        at expo.modules.updates.loader.Loader$downloadAllAssets$1.onFailure(Loader.kt:6)
        at expo.modules.updates.loader.FileDownloader$downloadAsset$1.onFailure(FileDownloader.kt:1)
        at expo.modules.updates.loader.FileDownloader$downloadFileToPath$1.onFailure(FileDownloader.kt:1)
        at expo.modules.updates.loader.FileDownloader$downloadData$1.onFailure(FileDownloader.kt:2)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:15)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
2022-05-25 08:22:54.200 22339-22426/host.exp.exponent E/LoaderTask: Unexpected error encountered while loading this app
    java.lang.Exception: Failed to load all assets
        at expo.modules.updates.loader.Loader.handleAssetDownloadCompleted(Loader.kt:24)
        at expo.modules.updates.loader.Loader.access$handleAssetDownloadCompleted(Loader.kt:1)
        at expo.modules.updates.loader.Loader$downloadAllAssets$1.onFailure(Loader.kt:6)
        at expo.modules.updates.loader.FileDownloader$downloadAsset$1.onFailure(FileDownloader.kt:1)
        at expo.modules.updates.loader.FileDownloader$downloadFileToPath$1.onFailure(FileDownloader.kt:1)
        at expo.modules.updates.loader.FileDownloader$downloadData$1.onFailure(FileDownloader.kt:2)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:15)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
2022-05-25 08:22:54.206 22339-22426/host.exp.exponent E/LoaderTask: Failed to download remote update
    java.lang.Exception: Failed to load all assets
        at expo.modules.updates.loader.Loader.handleAssetDownloadCompleted(Loader.kt:24)
        at expo.modules.updates.loader.Loader.access$handleAssetDownloadCompleted(Loader.kt:1)
        at expo.modules.updates.loader.Loader$downloadAllAssets$1.onFailure(Loader.kt:6)
        at expo.modules.updates.loader.FileDownloader$downloadAsset$1.onFailure(FileDownloader.kt:1)
        at expo.modules.updates.loader.FileDownloader$downloadFileToPath$1.onFailure(FileDownloader.kt:1)
        at expo.modules.updates.loader.FileDownloader$downloadData$1.onFailure(FileDownloader.kt:2)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:15)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

OK, I’m not 100% sure what’s going on there, but it seems to me like it’s having trouble loading the JS bundle for some reason.

and:

What happens if you replace the App.js with something like the default App.js as a test? Do you still get these errors?

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Doing this works, the app doesn’t crash.

OK, then I think you should try to narrow down the problem to find where in your code the problem is originating.

If a previous commit was working then check the changes you’ve made between then and the current version of the code. One way to do help with this is to use git bisect, but if it’s only a small number of changes it might be easy enough to just look at the changes manually.

Otherwise, try commenting out half of your code. If you no longer get the error it is likely coming from the commented out part of your code. If you still get the error then it is likely coming from the part that you did not comment out.

Based on the above, try commenting out another part of the code (e.g. take the half that you think the problem is coming from and comment out just half of that code.)

i.e. do a bisection search on your code to find where the error is coming from. (a.k.a. binary search)

I understand this might be a bit tricky depending on how your code is structured, but give it a try.

Alternatively, create a new app and start copying code into it from your real app and see when the error starts happening.

EDIT: Git bisect info:

@wodin thanks for your recommendation. I did follow it and observe that the app crashes with Unexpected error encountered while loading this app java.lang.Exception: Failed to load all assets before metro Bundler completes bundling, the bundler gets to around 80% before the app crashes.

After app crash, I then close the expo go app and restart it pressing a on the command line, this opens expo and the app works fine.

My observation is that the app is attempting to get some file before bundling completes which results into the failed to load all assets error.

Is there a way to ensure the bundler completes before app the boot.

@wodin Here’s an log before the crash happens

2022-05-25 12:20:41.195 5054-5152/host.exp.exponent W/unknown:ReactNative: StatusBarModule: Ignored status bar change, current activity is null.
2022-05-25 12:20:41.220 5054-5152/host.exp.exponent I/chatty: uid=10169(host.exp.exponent) mqt_native_modu identical 3 lines
2022-05-25 12:20:41.220 5054-5152/host.exp.exponent W/unknown:ReactNative: StatusBarModule: Ignored status bar change, current activity is null.
2022-05-25 12:20:41.233 5054-5151/host.exp.exponent W/ReactNativeJS: EventEmitter.removeListener('url', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by `EventEmitter.addListener`.
2022-05-25 12:20:41.278 5054-5054/host.exp.exponent I/ReactNative: [GESTURE HANDLER] Gesture handler is already enabled for a parent view
2022-05-25 12:20:41.278 5054-5054/host.exp.exponent I/chatty: uid=10169(host.exp.exponent) identical 1 line
2022-05-25 12:20:41.289 5054-5054/host.exp.exponent I/ReactNative: [GESTURE HANDLER] Gesture handler is already enabled for a parent view
2022-05-25 12:20:42.175 5054-5236/host.exp.exponent D/b: Do not have cached source file for https://exp.host/@exponent/home/bundle?versionName=2.24.4
2022-05-25 12:20:42.343 5054-5164/host.exp.exponent W/a: Could not find listener for key: devicePushToken
2022-05-25 12:20:43.684 5054-5071/host.exp.exponent I/st.exp.exponen: Background concurrent copying GC freed 245412(12MB) AllocSpace objects, 39(1496KB) LOS objects, 34% free, 46MB/70MB, paused 287us total 216.569ms
2022-05-25 12:20:43.688 5054-5054/host.exp.exponent D/q: Successfully preloaded kernel bundle
2022-05-25 12:20:43.697 5054-5073/host.exp.exponent W/System: A resource failed to call close. 
2022-05-25 12:20:43.702 5054-5073/host.exp.exponent W/System: A resource failed to call close. 
2022-05-25 12:21:00.970 5054-5140/host.exp.exponent E/Loader: Failed to download asset with key null
    java.net.SocketTimeoutException: timeout
        at okio.f0.newTimeoutException(JvmOkio.kt:1)
        at okio.g.access$newTimeoutException(AsyncTimeout.kt:1)
        at okio.g$d.read(AsyncTimeout.kt:6)
        at okio.a0.d(RealBufferedSource.kt:7)
        at okio.a0.e0(RealBufferedSource.kt:1)
        at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:1)
        at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:2)
        at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:1)
        at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:25)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:4)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:27)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:22)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:7)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12)
        at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:16)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:6)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: java.net.SocketException: Socket closed
        at java.net.SocketInputStream.read(SocketInputStream.java:209)
        at java.net.SocketInputStream.read(SocketInputStream.java:144)
        at okio.s.read(JvmOkio.kt:5)
        at okio.g$d.read(AsyncTimeout.kt:3)
        at okio.a0.d(RealBufferedSource.kt:7) 
        at okio.a0.e0(RealBufferedSource.kt:1) 
        at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:1) 
        at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:2) 
        at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:1) 
        at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:25) 
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12) 
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:4) 
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12) 
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:27) 
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12) 
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:22) 
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12) 
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:7) 
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:12) 
        at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:16) 
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:6) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:923) 
2022-05-25 12:21:00.980 5054-5140/host.exp.exponent E/Loader: Failed to load all assets
    java.lang.Exception: Failed to load all assets
        at expo.modules.updates.loader.Loader.handleAssetDownloadCompleted(Loader.kt:24)

Hi

This doesn’t make much sense to me.

You appear to be getting a socket timeout error, but I think this should all be happening on your own network (between your computer and the device you’re running Expo Go on). Unless you’re running expo start in tunnel mode or something like that.

The original issue was with a standalone app, right? So any assets would have been coming from a CDN and should in theory have downloaded OK.

But the fact that it also says the following makes me wonder if there really is a timeout:

The above error is being logged here:

It would be useful to know what URL or filename etc. it’s getting the error for, but for that you’d probably have to patch some of the native code involved. I think logging the url, relativePath and maybe these filenames would help.

1 Like

Thanks for your help and suggestions @wodin

I was not able to resolve the issue with Expo, I switched to bare workflow and everything works fine.

That’s really strange, but I’m glad it’s working for you. Are you still building with EAS?

No, I am building locally and deploying with fastlane.

Thanks for the reply.