Ionic 4 android 9 CLEARTEXT http not permitted error

ionic 4 app sends http request for android version 6,7 but gives an error saying CLEARTEXT http traffic (not permitted). I have trying to solve this by adding android:usesCleartextTraffic="true"
but ionic default is true for usesCleartextTraffic.

and also i tried to change url http to https. but nothing works for me.

so i solved this issue temporarily by adding


 <domain includeSubdomains="true">localhost</domain>
 <domain includeSubdomains="true">YOUR-IP_ADDRESS</domain>

to my network_security_config.xml .

localhost for android version 6,7
YOUR_IP_ADDRESS for version 8,9

2 Likes

My Problem is same but i can’t solve this Link

have you solve the issue?

You must configurate config.xml with the next parameters:








Done the configutions mentioned here.But I am still facing the same issue.http calls failing in android 9 devices with response 0:URL null.

hi,

can you post your network config file and config.xml code here?

Thanks for your response

Please find the details below

  1. added this in 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 includeSubdomains="true">ourdomain.com</domain>
<domain includeSubdomains="true">subdomain.ourdomain.com</domain>
</domain-config>
</network-security-config>

2) added in config.xml

<platform name="android">
allow-intent href="market:*" />
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:usesCleartextTraffic="true" />
<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" />
1 Like

changing the API url to https looks like the only working solution.

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

Try with this code use your domain in abcd.com , do not change the localhost

2 Likes

Thanks, this works for me!

1 Like

it works as charm for me. Thanks buddy :slight_smile:

1 Like

Thanks Guys. It works for me. :star_struck: :star_struck: :star_struck:

1 Like