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

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

我做错了什么?


当前回答

    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

其他回答

可能你的端口被占用了。 尝试在不同的端口上运行:

adb reverse tcp:6666 tcp:6666
react-native run-android --port 6666

检查您正在使用的端口是否空闲

linux:

lsof | grep LISTEN

窗口:

netstat -an

关闭代理,如果你在android studio设置代理,默认使用代理

在数小时寻找答案之后。解决方案是将节点降级到版本12.4。

在我的例子中,我意识到这个错误只发生在节点版本12.6的react native 0.60版本中。

在某些情况下,您可能需要关闭React-native捆绑器的端口 用相同的进程重新运行应用程序

1.sudo kill -9 $(sudo lsof -t -i:9001)

2.npm start inside the project

3. react-native run-android

以下是我在不改变构建的情况下解决这个问题的方法:

1-关闭虚拟设备

2-在物理设备上测试-(它工作)

3-创建新的虚拟设备API 30 Android 10+

4-在新创建的虚拟设备上再次尝试,所有工作都像一个魅力。