React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
对我来说,这个错误是由react-native的升级引起的
从Android 9.0 (API级别28)开始,默认情况下禁用明文支持。
如果您检查了升级差异,您需要创建一个调试清单 android / app / src /调试/ AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
</manifest>
查看更多信息:https://stackoverflow.com/a/50834600/1713216
https://react-native-community.github.io/upgrade-helper/
其他回答
默认情况下,一个名为“Metro server”的小型JavaScript服务器运行在端口8081上。
您需要使此端口可用于此服务器启动。所以,
释放端口 关闭虚拟设备 “react-native run-android”。
如何释放端口?
http://tenbull.blogspot.com/2019/05/how-to-kill-process-currently-using.html
如何在windows中杀死当前使用本地主机端口的进程?
最重要的是,我从8升级了我的节点版本。X到10.x(最新),正如facebook建议的那样 @ https://facebook.github.io/react-native/docs/getting-started
在数小时寻找答案之后。解决方案是将节点降级到版本12.4。
在我的例子中,我意识到这个错误只发生在节点版本12.6的react native 0.60版本中。
我尝试了下面所有的解决方案,不同的人评论和回答。有时它工作,但有时没有一个解决方案为我工作.....此错误的最佳解决方案从物理设备卸载APK并再次运行应用程序…它100%适合我!!
步骤1 -
从物理设备上卸载APK
步骤2 -
进入Android文件夹cd Android
步骤3 -
输入命令Gradlew Clean
步骤4 -
输入Cd . .返回项目
步骤4 -
执行命令npx react-native Run -android或react-native Run -android
以下是我在不改变构建的情况下解决这个问题的方法:
1-关闭虚拟设备
2-在物理设备上测试-(它工作)
3-创建新的虚拟设备API 30 Android 10+
4-在新创建的虚拟设备上再次尝试,所有工作都像一个魅力。
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