React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
模拟器上的错误信息有点误导人。我用的是Macbook。我需要通过运行$ chmod 755 ./gradlew来更改android/gradlew的权限,然后可以构建应用程序并将其部署到android模拟器。
其他回答
以下是我在不改变构建的情况下解决这个问题的方法:
1-关闭虚拟设备
2-在物理设备上测试-(它工作)
3-创建新的虚拟设备API 30 Android 10+
4-在新创建的虚拟设备上再次尝试,所有工作都像一个魅力。
在我的例子中,模拟器的Wifi和移动数据是关闭的。
我的解决方案如下:
启动Metro服务器
$ react-native start
开始安卓
$ react-native run-android
如果看到错误提示“端口8081已被使用”,那么您可以终止该进程并重新运行
$ react-native start
参见React Native故障诊断页面。
在尝试了几种方法后,这对我来说很有效。
在文件node_modules\metro-config\src\defaults\blacklist.js中
替换:
var sharedBlacklist = [
/node_modules[/\\]react[/\\]dist[/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
希望这能有所帮助。
(快速回答)
在我的工作空间尝试解决这个问题后,我找到了一个解决方案。
此错误是因为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.