Could not get BatchedBridge, make sure your bundle is packaged correctly

今天在学习ReactNative时,研究到ReactNative嵌入到原生app时遇到的一个问题,导致程序跳转的时候就crash,错误日志如下:

java.lang.RuntimeException: Could not get BatchedBridge, make sure your bundle is packaged correctly
at com.facebook.react.cxxbridge.CatalystInstanceImpl.loadScriptFromAssets(Native Method)
at com.facebook.react.cxxbridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:37)
at om.facebook.react.cxxbridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:177)
at com.facebook.react.XReactInstanceManagerImpl$4.call(XReactInstanceManagerImpl.java:888)
at com.facebook.react.XReactInstanceManagerImpl$4.call(XReactInstanceManagerImpl.java:881)
at om.facebook.react.bridge.queue.MessageQueueThreadImpl$1.run(MessageQueueThreadImpl.java:74)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at   com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:148)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196) at java.lang.Thread.run(Thread.java:818)

几经查找,在facebook的github上的issues中找到了问题的解决方式,
链接 https://github.com/facebook/react-native/issues/9336
这是个已经被closed的问题,
看到国外的有人也受该问题的困扰,有人给了一下的链接
https://stackoverflow.com/questions/34175416/how-to-use-offline-bundle-on-android-for-react-native-project
中完美的解决了我的问题。

解决方法

在项目根目录里运行

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

之后可以看到在项目的assets目录下生成了了来了两个文件,如果没有先自行创建assets目录再运行(或者管理员模式打开cmd)
Could not get BatchedBridge, make sure your bundle is packaged correctly_第1张图片
重新运行问题解决

你可能感兴趣的:(Could not get BatchedBridge, make sure your bundle is packaged correctly)