Search code examples
javascriptjavaandroidreact-nativemetro-bundler

Android: JS Bundle not loading from Metro Bundler Server


On Android I was suddenly unable to get the metro bundler server to work. I've been debugging this for the past 5 hours, and I couldn't find any cause for this issue. Unlike in this issue, my app doesn't even start to show the LogBox red-error warning. It just immediately crashes.

Whenever I try to run the Android app (I've tried with all kinds of different settings, enabling/disabling Hermes, ABI splits, explicitly forcing an SoLoader version, stripping all kinds of code to get a minimal app, cleaning gradle cache, adding android:usesCleartextTraffic="true" to my AndroidManifest.xml, etc ...), the App starts with a Whitescreen and immediately crashes afterwards. I've managed to find some Exceptions in the Logcat:

2020-08-11 11:33:52.315 5176-5256/com.mrousavy.springsale E/GraphResponse: {HttpStatus: 400, errorCode: 100, subErrorCode: 33, errorType: GraphMethodException, errorMessage: Unsupported get request. Object with ID '290453355515078' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api}
2020-08-11 11:33:52.316 5176-5256/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-11 11:33:52.316 5176-5264/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-11 11:33:52.316 5176-5256/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-11 11:33:52.316 5176-5256/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
2020-08-11 11:33:52.346 5176-5279/com.mrousavy.springsale E/ReactNativeJNI: logMarker CREATE_REACT_CONTEXT_END
2020-08-11 11:33:52.347 5176-5274/com.mrousavy.springsale E/unknown:ReactNative: ReactInstanceManager.createReactContext: mJSIModulePackage null
2020-08-11 11:33:52.350 5176-5274/com.mrousavy.springsale E/unknown:DisabledDevSupportManager: Caught exception
    java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
        at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
        at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:234)
        at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:29)
        at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:258)
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1293)
        at com.facebook.react.ReactInstanceManager.access$1100(ReactInstanceManager.java:131)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1016)
        at java.lang.Thread.run(Thread.java:919)
    
    
    --------- beginning of crash
2020-08-11 11:33:52.352 5176-5274/com.mrousavy.springsale E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: com.mrousavy.springsale, PID: 5176
    java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
        at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
        at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:234)
        at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:29)
        at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:258)
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1293)
        at com.facebook.react.ReactInstanceManager.access$1100(ReactInstanceManager.java:131)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1016)
        at java.lang.Thread.run(Thread.java:919)
2020-08-11 11:33:52.498 13316-13413/? E/ActivityThread: Failed to find provider info for com.google.android.apps.wellbeing.api
2020-08-11 11:33:52.725 5176-5237/com.mrousavy.springsale D/libcrashlytics: Initializing libcrashlytics version 2.0.5
2020-08-11 11:33:52.725 5176-5237/com.mrousavy.springsale D/libcrashlytics: Initializing native crash handling successful.
2020-08-11 11:33:52.726 5176-5237/com.mrousavy.springsale I/FirebaseCrashlytics: Crashlytics NDK initialization successful
2020-08-11 11:33:52.743 5176-5263/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2020-08-11 11:33:52.743 5176-5263/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
2020-08-11 11:33:52.743 5176-5263/com.mrousavy.springsale W/FirebaseRemoteConfig: No value of type 'FirebaseRemoteConfigValue' exists for parameter key 'fpr_session_max_duration_min'.
2020-08-11 11:33:52.744 5176-5263/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
2020-08-11 11:33:52.744 5176-5263/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-11 11:33:52.744 5176-5263/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
2020-08-11 11:33:52.744 5176-5263/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
2020-08-11 11:33:52.745 5176-5263/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-11 11:33:52.745 5176-5263/com.mrousavy.springsale I/chatty: uid=10146(com.mrousavy.springsale) pool-25-thread- identical 1 line
2020-08-11 11:33:52.746 5176-5263/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-11 11:33:52.750 5176-5264/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2020-08-11 11:33:52.823 2030-5291/? W/ActivityTaskManager:   Force finishing activity com.mrousavy.springsale/.MainActivity
2020-08-11 11:33:52.824 2030-5288/? I/DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
2020-08-11 11:33:52.836 5176-5274/com.mrousavy.springsale I/Process: Sending signal. PID: 5176 SIG: 9
2020-08-11 11:33:52.837 2030-2057/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
2020-08-11 11:33:52.838 2030-2057/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
2020-08-11 11:33:52.930 2030-2130/? W/InputDispatcher: channel '4b40fe1 com.mrousavy.springsale/com.mrousavy.springsale.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
2020-08-11 11:33:52.930 2030-2130/? E/InputDispatcher: channel '4b40fe1 com.mrousavy.springsale/com.mrousavy.springsale.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2020-08-11 11:33:52.936 2030-3089/? I/WindowManager: WIN DEATH: Window{4b40fe1 u0 com.mrousavy.springsale/com.mrousavy.springsale.MainActivity}
2020-08-11 11:33:52.936 2030-3089/? W/InputDispatcher: Attempted to unregister already unregistered input channel '4b40fe1 com.mrousavy.springsale/com.mrousavy.springsale.MainActivity (server)'
2020-08-11 11:33:52.938 2030-2376/? I/ActivityManager: Process com.mrousavy.springsale (pid 5176) has died: vis+99 TOP 

When I manually create the JS bundle using the following command:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

I managed to successfully start the App through Android Studio, but of course this is not a solution, as I have to run this command every time I change something (even in JS), so I don't have live-reload anymore, I don't have console.logs, and I have a terrible development experience.

So in short: Somehow my app can't stream the bundle over the metro bundler server on localhost anymore, but it works when I manually create the bundle. It doesn't even start the Metro Bundler! On iOS it works.


Solution

  • So it turns out this was a dependencies issue. In case anyone else hits this problem, compare your project with the "template" project (in the react-native repo), especially look at all the versions in package.json! For me, I had metro-config 0.65 which was too new for RN 0.63.