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


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.


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"?>
<base-config cleartextTrafficPermitted="true">
<certificates src="system" />
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true"></domain>
<domain includeSubdomains="true"></domain>

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="">
<application android:usesCleartextTraffic="true" />
<application android:networkSecurityConfig="@xml/network_security_config" />
<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />

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

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

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


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

Thanks sir, it was worked!

Thank you! You saved my time!

I am working on ionic 5 using capacitor. I tried to call an Larvel api from localhost but am getting this error

First I got the below error
There was an error with the request: Cleartext HTTP traffic to localhost not permitted ionic

Fixed doing below in AndroidManifest.xml



Error changes
There was an error with the request: Failed to connect to localhost/

I did not see any file in ionic 5 with the name:

Ionic Info:

Ionic CLI : 6.11.11 (C:\Users\Ahmad Raza Mughal\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 5.3.5
@angular-devkit/build-angular : 0.1000.8
@angular-devkit/schematics : 10.0.8
@angular/cli : 10.0.8
@ionic/angular-toolkit : 2.3.3


Capacitor CLI : 2.4.2
@capacitor/core : 2.4.2


cordova-res : 0.14.0
native-run : 1.0.0


NodeJS : v12.16.2 (C:\Program Files\nodejs\node.exe)
npm : 6.14.4
OS : Windows 10

Please help with the above?



check the network_config file in your folder path\resources\android\xml and change as the solution given.

I created this file manually in AndroidStudio and it’s works for me!
Try to create res/xml/network_security_config.xml with text described above, and put link to it in “application” section in AndroidManifest.xml (like this: application android:networkSecurityConfig="@xml/network_security_config")