Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 276
Andrew Wijaya Avatar asked Dec 23 '22 23:12

Andrew Wijaya


1 Answers

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.

like image 110
Cheezey Avatar answered Dec 25 '22 23:12

Cheezey