Unable to load script. Make sure you'reeither running a Metro server(run react-native start )or t...

Unable to load script. Make sure you'reeither running a Metro server(run react-native start )or that your bundle ‘index. android.bundle’ is packaged correctly for release

从git上clone下来的项目

在Android 环境配置完成,并且外接手机设备没有问题。
运行npm run android 出现上面异常

查看项目目录下->android->app->src是否有debug文件夹
如没有 新建debug文件夹->新建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>

注:这个问题是因为Android9.0以上禁止了所有http请求,为了安全。所以手机设备和node服务不能通讯,我们配置src的debug的AndroidManifest.xml 文件 允许在debug模式下进行明文通讯(android:usesCleartextTraffic="true")

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容