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

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

我做错了什么?


当前回答

对我有用的是:

关闭所有控制台 打开一个新的控制台 $ adb设备 确保你只连接了一个设备 $ react-native run-android

其他回答

试试这个

taskkill /F /IM node.exe

然后

npx react-native run-android

我的解决方案如下:

启动Metro服务器

$ react-native start

开始安卓

$ react-native run-android

如果看到错误提示“端口8081已被使用”,那么您可以终止该进程并重新运行

$ react-native start

参见React Native故障诊断页面。

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

这适用于我,另外添加端口号和运行android

npx react-native run-android --port=8082 (maybe port number differs)
    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