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

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

我做错了什么?


当前回答

重要, 您的环境中可能有许多Virtual设备。如果您正在更改AVD,请确保再次重复设置。

调试信息,

如果您遇到上述错误,您必须首先验证端口8081上正在运行什么

最快的方法是在终端中使用以下命令

netstat -aon | findstr 8081

如果显示了什么,就意味着端口被阻塞了。如果可能的话,解除那个端口的封锁。

否则,您将需要更改端口。Naveen Kumar在上面的评论中已经提到了这个过程

react-native run-android --port=9001

确保9001也没有被使用:)

其他回答

这是由于android设备无法连接到地铁服务器。如果上面的不起作用,检查一下你的android设备是否配置了代理。(设置>代理>不代理)。

我也遇到过这个问题。我解决了下面这一步。

在Environment Veritable中检查android sdk路径。

添加 系统变量中的ANDROID_HOME = C:\Users\user_name\AppData\Local\Android\Sdk 而且 C:\Users\user_name\AppData\Local\Android\Sdk\platform-tools路径在“系统变量”中

替换sharedBlacklist如下代码段

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

在node_modules / metro-config / src / / blacklist.js违约

然后执行npx react-native run-android——port 9001

编码. .快乐!

    this works for me on ubuntu
    
    1. if you are having node version 17 first downgrade its version:-
    You can use n for node's version management.
    
    this is very easy to use.
    $ npm install -g n
    
    then you can show your node version:
    $ node -v
    v16.13.2
    
    2. create an assets folder inside root of the project:-
    project\android\app\src\main\assets
    set folder name should be assets

3. now the final step implement the given code inside the project folder:- 

$cd project 
/project$ 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

4. after following all these step react-native was successfully running on my pc

你还没有启动捆扎机呢。在项目的根目录下运行npm start或react-native start,然后再执行react-native Run -android。

默认情况下,一个名为“Metro server”的小型JavaScript服务器运行在端口8081上。

您需要使此端口可用于此服务器启动。所以,

释放端口 关闭虚拟设备 “react-native run-android”。

如何释放端口?

http://tenbull.blogspot.com/2019/05/how-to-kill-process-currently-using.html

如何在windows中杀死当前使用本地主机端口的进程?

最重要的是,我从8升级了我的节点版本。X到10.x(最新),正如facebook建议的那样 @ https://facebook.github.io/react-native/docs/getting-started