我在手机上运行时得到ERR_CLEARTEXT_NOT_PERMITTED。但是它在webview和模拟器上运行良好

And*_*aya 3 android ionic-framework ionic4

我在该项目上使用Laravel Echo Ionic。在移动设备上运行它时,我收到ERR_CLEARTEXT_NOT_PERMITTED错误,但在Webview和模拟器上运行良好。

我试图添加

<uses-permission android:name=“android.permission.INTERNET” />
<uses-permission android:name=“android.permission.ACCESS_NETWORK_STATE” />
<uses-permission android:name=“android.permission.ACCESS_WIFI_STATE” />
Run Code Online (Sandbox Code Playgroud)

在,AndroidManifest.xml但是,它不起作用。

我试图添加

<access origin=“*”/>
<allow-intent href=“*” />
<allow-navigation href=“*” />
Run Code Online (Sandbox Code Playgroud)

在config.xml上。

最后我尝试用修改config.xml

<edit-config file=“app/src/main/AndroidManifest.xml” mode=“merge” target=“/manifest/application”>
   <application android:usesCleartextTraffic=“true” />
</edit-config>
Run Code Online (Sandbox Code Playgroud)

但一切都不适合我。

任何想法如何解决此问题?

Che*_*zey 7

这只是最近发生在我身上,如果您尝试从设备连接到任何外部服务器(由于您提到了laravel echo,那么我认为您正在尝试连接到IP),那么也许可以尝试一下。

如果您注意到,位于“ resources”文件夹中的network_security_config.xml将被复制到您的android“ app”文件夹中

...

<platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:networkSecurityConfig="@xml/network_security_config" />
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
        <allow-intent href="market:*" />
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
...
</platform>
...
Run Code Online (Sandbox Code Playgroud)

也许尝试将位于resources / android / xml / network_security_config.xml中的network_security_config.xml文件修改为:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain>localhost</domain>
        <domain>your_external_ip_here</domain>
    </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

希望能有所帮助。