React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
嘿,伙计们,两个按钮的组合解决了我的问题。这与港口有关。
adb reverse tcp:8088 tcp:8088
react-native run-android --port=8088
通过这样做,应用程序可以通过USB连接我的手机。 我认为我的AV或Vagrant或PC中的其他东西正在使用该端口。
如果需要,您可以将8088更改为其他内容。
享受吧!
其他回答
首先执行步骤4和5,然后可以运行项目。如果您没有得到结果(步骤4和5),请执行以下步骤
1-尝试降级你的Node版本(当前版本是12.13.1)
choco uninstall nodejs
choco install nodejs --version 12.8
2-添加npm模块的路径(C:\Users\your user name\AppData\Roaming\npm)到系统变量而不是用户变量
3-使用命令全局安装react native
npm install -g react-native-cli
4-进入项目目录的根目录,执行以下命令:
react-native start
5-打开项目根目录下的另一个终端,执行以下命令:
react-native run-android
编辑:
你在用Genymotion ?是,执行以下步骤。
在以上步骤后,如果您得到以下错误?
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
打开你的genymotion,转到:
genymotion菜单->设置-> ADB ->然后选择使用自定义android sdk工具(点击浏览找到sdk位置)
最后,再次运行您的项目。
你还没有启动捆扎机呢。在项目的根目录下运行npm start或react-native start,然后再执行react-native Run -android。
如果你在Linux操作系统上运行,可能会出现npm远程服务器不运行的情况。打开另一个终端(带有项目目录),在执行sudo react-native run-android之前,运行sudo npm start或sudo react-native start命令
(快速回答)
在我的工作空间尝试解决这个问题后,我找到了一个解决方案。
此错误是因为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.
下面这些步骤真的对我很有帮助:
步骤1:在android/app/src/main/assets目录下创建一个目录
Linux命令:mkdir android/app/src/main/assets
第二步:将index.android.js(在根目录下)重命名为index.js(也许有一个index.js文件,在这种情况下你不需要重命名它),然后运行以下命令:
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
步骤3: 构建APK: react-native run-android
请在最新版本使用index.js。
享受:)