Android: 从Metro Bundler服务器加载JS捆绑包失败

huangapple go评论101阅读模式
英文:

Android: JS Bundle not loading from Metro Bundler Server

问题

在Android上,我突然无法使metro捆绑服务器工作。我已经为此调试了过去5个小时,但我找不到任何原因。与this问题不同,我的应用程序甚至不会开始显示LogBox红色错误警告。它立即崩溃。

每当我尝试运行Android应用程序(我尝试过各种不同的设置,启用/禁用Hermes,ABI分割,明确强制SoLoader版本,剥离各种代码以获得最小的应用程序,清除gradle缓存,将android:usesCleartextTraffic="true"添加到我的AndroidManifest.xml等...),应用程序都会以白屏启动,然后立即崩溃。我设法在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
<details>
<summary>英文:</summary>
On Android I was suddenly unable to get the metro bundler server to work. I&#39;ve been debugging this for the past 5 hours, and I couldn&#39;t find any cause for this issue. Unlike in [this](https://github.com/facebook/react-native/issues/25348) issue, my app doesn&#39;t even start to show the LogBox red-error warning. It just immediately crashes.
Whenever I try to run the Android app (I&#39;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=&quot;true&quot;` to my `AndroidManifest.xml`, etc ...), the App starts with a Whitescreen and immediately crashes afterwards. I&#39;ve managed to find some Exceptions in the Logcat:
```log
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 &#39;290453355515078&#39; 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;-&gt;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;-&gt;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;-&gt;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;-&gt;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&#39;re either running a Metro server (run &#39;react-native start&#39;) or that your bundle &#39;index.android.bundle&#39; 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&#39;re either running a Metro server (run &#39;react-native start&#39;) or that your bundle &#39;index.android.bundle&#39; 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;-&gt;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;-&gt;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 &#39;FirebaseRemoteConfigValue&#39; exists for parameter key &#39;fpr_session_max_duration_min&#39;.
2020-08-11 11:33:52.744 5176-5263/com.mrousavy.springsale W/savy.springsal: Accessing hidden method Lsun/misc/Unsafe;-&gt;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;-&gt;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;-&gt;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;-&gt;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;-&gt;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;-&gt;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;-&gt;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 &#39;4b40fe1 com.mrousavy.springsale/com.mrousavy.springsale.MainActivity (server)&#39; ~ Consumer closed input channel or an error occurred.  events=0x9
2020-08-11 11:33:52.930 2030-2130/? E/InputDispatcher: channel &#39;4b40fe1 com.mrousavy.springsale/com.mrousavy.springsale.MainActivity (server)&#39; ~ 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 &#39;4b40fe1 com.mrousavy.springsale/com.mrousavy.springsale.MainActivity (server)&#39;
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.

答案1

得分: 0

这是一个依赖关系的问题。如果有其他人遇到这个问题,可以将你的项目与“模板”项目(在react-native存储库中)进行比较,特别是查看package.json中的所有版本!对我来说,我使用了metro-config 0.65,这对于RN 0.63来说太新了。

英文:

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.

huangapple
  • 本文由 发表于 2020年8月11日 18:18:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/63356131.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定