React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
我尝试了下面所有的解决方案,不同的人评论和回答。有时它工作,但有时没有一个解决方案为我工作.....此错误的最佳解决方案从物理设备卸载APK并再次运行应用程序…它100%适合我!!
步骤1 -
从物理设备上卸载APK
步骤2 -
进入Android文件夹cd Android
步骤3 -
输入命令Gradlew Clean
步骤4 -
输入Cd . .返回项目
步骤4 -
执行命令npx react-native Run -android或react-native Run -android
其他回答
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
重要, 您的环境中可能有许多Virtual设备。如果您正在更改AVD,请确保再次重复设置。
调试信息,
如果您遇到上述错误,您必须首先验证端口8081上正在运行什么
最快的方法是在终端中使用以下命令
netstat -aon | findstr 8081
如果显示了什么,就意味着端口被阻塞了。如果可能的话,解除那个端口的封锁。
否则,您将需要更改端口。Naveen Kumar在上面的评论中已经提到了这个过程
react-native run-android --port=9001
确保9001也没有被使用:)
M1芯片
验证您的JAVA_HOME路径,在我的M1芯片的情况下,我将其定义为.zprofile
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
然后执行source ~/。终端z型线
在这之后,它对我起作用了。
我在学习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。
我得到了同样的问题,在遵循以下步骤后,它得到了解决的问题
清晰的守望人守望:守望人守望一切。 删除“node_modules”文件夹:rm -rf node_modules && npm install。 Reset Metro Bundler cache: rm -rf /tmp/ Metro - Bundler -cache-* 删除急速缓存:rm -rf /tmp/急速-map-react-native-packager-*