React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
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
其他回答
这种错误的可能性也是错误的路径,检查一次
export ANDROID_HOME=/Users/microrentindia/Library/Android/sdk/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
我只是想补充一个这里没有提到的不明显的可能性。我正在使用@react-native-community/netinfo来检测网络变化,主要是网络状态。为了测试网络关闭状态,需要关闭模拟器上的WIFI开关。这也有效地切断了模拟器和调试环境之间的桥梁。测试结束后,我没有重新开启WIFI,因为我离开了电脑,回来后很快就忘了这事。
其他人也有可能是这种情况,在采取任何其他激烈步骤之前,值得检查一下。
你还没有启动捆扎机呢。在项目的根目录下运行npm start或react-native start,然后再执行react-native Run -android。
我的解决方案如下:
启动Metro服务器
$ react-native start
开始安卓
$ react-native run-android
如果看到错误提示“端口8081已被使用”,那么您可以终止该进程并重新运行
$ react-native start
参见React Native故障诊断页面。
在某些情况下,您可能需要关闭React-native捆绑器的端口 用相同的进程重新运行应用程序
1.sudo kill -9 $(sudo lsof -t -i:9001)
2.npm start inside the project
3. react-native run-android