React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
像我们大多数人一样,我假设你运行的是VSCODE。对我来说,我跑了
NPX react-native start
从一个单独的终端
现在在VSCODE中从你的终端运行npx react-native run-android
其他回答
显然,没有一个答案能帮我解决这个问题。我能够在模拟器上运行反应本机应用程序,但相同的代码(即使服务器正在运行),在设备上运行应用程序时给了我这个错误。
我能够通过在终端中执行以下命令来解决它:
Adb reverse tcp:8081 tcp:8081
(快速回答)
在我的工作空间尝试解决这个问题后,我找到了一个解决方案。
此错误是因为Metro使用NPM和Node版本的某些组合时出现了问题。
你有两个选择:
Alternative 1: Try to update or downgrade npm and node version. Alternative 2: Go to this file: \node_modules\metro-config\src\defaults\blacklist.js and change this code: var sharedBlacklist = [ /node_modules[/\\]react[/\\]dist[/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; and change to this: var sharedBlacklist = [ /node_modules[\/\\]react[\/\\]dist[\/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; Please note that if you run an npm install or a yarn install you need to change the code again.
对我有用的是:
关闭所有控制台 打开一个新的控制台 $ adb设备 确保你只连接了一个设备 $ react-native run-android
如果你已经尝试了上述解决方案中的所有方法,可以尝试以下步骤:
在android/app/src/main/assets中创建文件 执行如下命令:
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
现在运行命令构建react-native run-android
这是由于android设备无法连接到地铁服务器。如果上面的不起作用,检查一下你的android设备是否配置了代理。(设置>代理>不代理)。