ERR_CLEARTEXT_NOT_PERMITTED in debug app on Android

thanks bro.

  • config xml:
<preferance name="android-usesCleartextTraffic" value="true" />
  <allow-navigation href="*" />

  • network_security_config.xml:
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">localhost</domain>
    <domain includeSubdomains="true">http://domain>
  </domain-config>
</network-security-config>

  • AndroidManifest.xml:

android:networkSecurityConfig="@xml/network_security_config"
android:usesCleartextTraffic="true"
1 Like

Read the steps:

I signed up just to thanks man. It fixed my problem…Great work… :grinning:

Yes, this solution worked for me. thansk @Umud

Thanks, worked fine!

Tried a ton of options, per one poster adding the below to my resources/android/xml/network_security_config.xml did the trick!

<base-config cleartextTrafficPermitted="true">
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
</base-config>
1 Like

after use this code i cannot use my applicatiob above android 8 please help me to fix the issue

1 Like

Hi @akhilashok7539 welcome to the community!
After all of this tries, If any one of this alternatives don’t works for you.
May you to check your Api backend and use https on it by a SSL certificate.
It seem me the origin from this problem.

Hi,
Do i need to add this changes even my server is https?

Hello,
No if your api url has SSL, you do not need to add this settings. Start your api url with https:// will be enough.

Your error is not releated with “cleartext” . As I see your api request is success but the result is not Ok. Please check your api.

Its working as expected in android version < 7 but in the above versions getting above error. Any help.

hi in my case i add some code and works now ::: my app didnt work in android 10 and give me the same error

in resources/android/xml/network_security_config.xml >>

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true"></base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">opencart-ir.com(your domain)</domain> 
    </domain-config>
</network-security-config>

in config.xml >>
at the start after tag i add

     ......................
    <content src="index.html" />
    <access origin="*" />
     ......................

and in the middel in tag i added below code

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

and at least i add in /platform/android/app/src/AndroidManifest.xml

    <application 
      ...............
       android:networkSecurityConfig="@xml/network_security_config"  
       android:usesCleartextTraffic="true"
         ......
></application>
      ```

and ionic cordova build android 
I hope it will help you
1 Like

that works for me, thanks a lot :slight_smile:

3 Likes

This worked for me!! Tested on Ionic 5 using Capacitor.

1 Like

Worked for me! Can sleep in peace now :smile:

good morning forum can someone tell me the correct steps I’m working with ionic, to generate my android project because I get the same error and when I generate my project does not create the network_security_config.xml file.

thanks it worked for me

thanks , this worked for me

Maybe could you simply add it on your capacitor.config.json

"server":{
  "cleartext": true,
  ...
}
1 Like