4

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?

4 Answers 4

12

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.

3
  • 1
    wow, thanks!! That was quick reply. It works perfectly after I remove and rebuild android platform. May 22, 2019 at 17:20
  • 1
    It's my pleasure :)
    – Cheezey
    May 22, 2019 at 17:20
  • Still i facing that problem help @Cheezey
    – jose
    Nov 6, 2019 at 13:04
2
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

1
  • Where is the network_security_config.xml exactly ? Is it in my ionic projects folder ? As it is I do not have network_security_config.xml Can you specify the network_security_config.xml?
    – GhostDede
    Feb 14, 2020 at 12:48
1

To run it on mobile devices you need to make some configurations in your project, following the file path below you will arrive at three possible solutions

resources/android/xml/network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
     <base-config cleartextTrafficPermitted="true">
       <trust-anchors>
           <certificates src="system" />
       </trust-anchors>
   </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain>localhost</domain>
        <domain includeSubdomains="true">YOUR DOMAIN/IP</domain>
    </domain-config>
</network-security-config>

config.xml

<access origin="*" />
<platform name="android">
        <preference name="Scheme" value="http" />
        <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" />
            <application android:usesCleartextTraffic="true" />
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
  </platform>

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

<application android:usesCleartextTraffic="true">
-2

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>

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.