React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:

无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。

我做错了什么?


当前回答

我也遇到过类似的问题。NPX react-native init创建。gitignore文件,忽略<project>/android/app/src/debug文件夹。如果您稍后克隆了此项目,则该文件夹将会丢失。 解决办法很简单。以后将这一行添加到.gitignore文件的底部。

! android / app / src /调试

对于当前项目,请项目创建者提交此文件夹。 我在react原生版本0.63中遇到过这个错误

其他回答

在我的例子中,我只是关闭了app form模拟器 然后再运行一次

react-native运行android

我尝试了下面所有的解决方案,不同的人评论和回答。有时它工作,但有时没有一个解决方案为我工作.....此错误的最佳解决方案从物理设备卸载APK并再次运行应用程序…它100%适合我!!

步骤1 -

从物理设备上卸载APK

步骤2 -

进入Android文件夹cd Android

步骤3 -

输入命令Gradlew Clean

步骤4 -

输入Cd . .返回项目

步骤4 -

执行命令npx react-native Run -android或react-native Run -android

下面这些步骤真的对我很有帮助:

步骤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。

享受:)

请检查地铁服务器是否正在运行任何其他端口。如果有,停止所有服务器,然后重新启动服务器,再试一次。

(快速回答)

在我的工作空间尝试解决这个问题后,我找到了一个解决方案。

此错误是因为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.