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

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

我做错了什么?


当前回答

我也遇到过类似的问题。NPX react-native init创建。gitignore文件,忽略<project>/android/app/src/debug文件夹。如果您稍后克隆了此项目,则该文件夹将会丢失。 解决办法很简单。以后将这一行添加到.gitignore文件的底部。

! android / app / src /调试

对于当前项目,请项目创建者提交此文件夹。 我在react原生版本0.63中遇到过这个错误

其他回答

显然,没有一个答案能帮我解决这个问题。我能够在模拟器上运行反应本机应用程序,但相同的代码(即使服务器正在运行),在设备上运行应用程序时给了我这个错误。

我能够通过在终端中执行以下命令来解决它:

Adb reverse tcp:8081 tcp:8081

我也遇到过这个问题。我解决了下面这一步。

在Environment Veritable中检查android sdk路径。

添加 系统变量中的ANDROID_HOME = C:\Users\user_name\AppData\Local\Android\Sdk 而且 C:\Users\user_name\AppData\Local\Android\Sdk\platform-tools路径在“系统变量”中

替换sharedBlacklist如下代码段

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

在node_modules / metro-config / src / / blacklist.js违约

然后执行npx react-native run-android——port 9001

编码. .快乐!

你可以尝试以下方法:

在AndroidManifest.xml中添加这一行

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

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

在我的例子中,我试图在模拟器上运行应用程序。但是,我得到了这个

这个IP 10.0.2.2可以从模拟器chrome浏览器访问。问题是这个IP不在Android网络安全设置白名单中。所以,无论你在这里看到的IP地址添加到下面的设置,你就可以开始了。

./android/app/src/main/AndroidManifest.xml

        <application
                android:name=".MainApplication"
+               android:usesCleartextTraffic="true"   <- Add this line
                android:allowBackup="true"
                android:label="@string/app_name"
                android:icon="@mipmap/ic_launcher"

./android/app/src/main/res/xml/network_security_config.xml
</network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">10.0.1.1</domain>
        <domain includeSubdomains="true">10.0.2.2</domain>
        <domain includeSubdomains="true">10.0.3.2</domain>
    </domain-config>
 </network-security-config>

只需将<domain inclesubdomains ="true">10.0.2.2</domain>替换为react-native错误中显示的IP。

这种错误的可能性也是错误的路径,检查一次

 export ANDROID_HOME=/Users/microrentindia/Library/Android/sdk/
 export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools