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

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

我做错了什么?


当前回答

试试这个

taskkill /F /IM node.exe

然后

npx react-native run-android

其他回答

在我的例子中,模拟器的Wifi和移动数据是关闭的。

我在学习React Native教程时也遇到过同样的问题(在Linux上开发,目标是Android)。

这个问题帮助我通过以下步骤解决了问题。按如下顺序执行以下命令:

(在项目目录)mkdir android/app/src/main/assets 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 react-native运行android

您可以通过将上述步骤放在包的脚本部分来自动化它们。Json是这样的:

"android-linux": "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 && react-native run-android"

然后你可以每次都从你的命令行执行npm run android-linux。

    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

模拟器上的错误信息有点误导人。我用的是Macbook。我需要通过运行$ chmod 755 ./gradlew来更改android/gradlew的权限,然后可以构建应用程序并将其部署到android模拟器。

我做了: 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

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