简体   繁体   中英

I get ERR_CLEARTEXT_NOT_PERMITTED while running on my mobile. But it is running fine on webview and emulator

I am using Laravel Echo Ionic on the project. I get ERR_CLEARTEXT_NOT_PERMITTED error while running it on mobile devices but it is running fine on webview and emulator.

I have tried to add

<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” />

on AndroidManifest.xml but, it doesn't work.

and i've tried to add

<access origin=“*”/>
<allow-intent href=“*” />
<allow-navigation href=“*” />

on config.xml.

and lastly i've tried to modify config.xml with

<edit-config file=“app/src/main/AndroidManifest.xml” mode=“merge” target=“/manifest/application”>
   <application android:usesCleartextTraffic=“true” />
</edit-config>

but all doesn't work for me.

Any idea how to fix this problem?

It just happened to me recently and if you are trying to connect from your device to any external server (since you mention about laravel echo, then I assume that you are trying to connect to an IP), then maybe you can try this.

If you notice, the network_security_config.xml located in "resources" folder will be copied into your android "app" folder

...

<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>
...

Maybe try to modify network_security_config.xml file located in resources/android/xml/network_security_config.xml into :

<?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>

Hope this help.

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">173.249.51.122</domain>
    </domain-config>
</network-security-config>

Enter Only IP address (No http:// or https://). It's work for me

My network_security_config.xml file some changes in it you can try. This is worked for me. Add your IP address

<?xml version="1.0" encoding="utf-8"?><network-security-config>
<domain-config cleartextTrafficPermitted="true">
    <domain>localhost</domain>
      <domain>http://192.168.0.51:8082/hbpms"</domain>
</domain-config>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM