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

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

我做错了什么?


当前回答

试试这个

taskkill /F /IM node.exe

然后

npx react-native run-android

其他回答

M1芯片

验证您的JAVA_HOME路径,在我的M1芯片的情况下,我将其定义为.zprofile

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"

然后执行source ~/。终端z型线

在这之后,它对我起作用了。

我遇到了同样的麻烦,对我来说,问题是adb不在正确的环境路径,错误是告诉你地铁端口,而你在adb,端口被杀死并重新启动。

添加环境变量(ADB)

开放环境变量 从第二帧PATH变量中选择,然后单击下面的编辑选项 点击添加选项 提交sdk平台工具路径C:\Users\ My User \AppData\Local\Android\ sdk \platform-tools

注意:或取决于adb.exe在您的机器中的位置

保存更改

再次运行android build

$ react-native run-android

Or

$ react-native start

$ react-native run-android

你可以尝试以下方法:

在AndroidManifest.xml中添加这一行

<application
[...]
android:usesCleartextTraffic="true"
/>
[...]
</application>

编辑: 注意,为了应用程序的安全性,在生产环境中它必须为假

我做了: react-native开始 而且 NPX react-native run-android。

然而,对于Min19,(基于Ubuntu的)我也有同样的问题,直到我运行:

echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

来自: https://reactnative.dev/docs/troubleshooting#content

至少我手机里还有软件在运行。

    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