ERR_CLEARTEXT_NOT_PERMITTED in debug app on Android

just to sum it up
i’ve got this working on ionic v4 tho i consider it doesnt matter

  1. you should have this option set under android prefernces in config.xml (note that without xmlns:android=**** line i am getting errors)
<access origin="*" />
<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>
  1. next - under “resources/android/xml/network_security_config.xml” if you have https connection with self singed certificate you should add
<network-security-config>
   <base-config cleartextTrafficPermitted="true">
       <trust-anchors>
           <certificates src="system" />
       </trust-anchors>
   </base-config>
</network-security-config>
  1. include all ur http calls to DOMAINS under this option
<network-security-config>
   <base-config cleartextTrafficPermitted="true">
      ******
   </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">URDOMAIN_NOT_IP.com</domain>
    </domain-config> </network-security-config>
</network-security-config>
  1. consider reading official documentation as well

if it still is not working, try to take a look in AndroidManifest.xml in build, to take a look if something is wrong

1 Like

worked for me :slight_smile: tks

1 Like

Just Replace this:

<application android:networkSecurityConfig="@xml/network_security_config" />

and Add this:

<application android:usesCleartextTraffic="true" />

Example config.xml:

<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" />
</edit-config>

I hope to solve your problem.

1 Like

It Worked ! ,thanks buddy ,i just signup to say thanks a lot ,wish you all the best

Im using IONIC 5.4.13, cordova 9.0.0 (cordova-lib@9.0.1)

I might be repeating information but for me problem started appearing after adding some plugin (not sure yet). I tried all above combinations, but nothing worked. It only started working after adding:

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

to file in project at

resources/android/xml/network_security_config.xml

so my network_security_config.xml file now looks like:

<?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">localhost</domain>
        <domain includeSubdomains="true">10.1.25.10</domain>
    </domain-config>
</network-security-config>

Thanks to all.

5 Likes

thanks worked for me

Thank you, this worked for me.

With the base-config section added, it works for me. thank you very much.

Funciono para mi, que no me ejecutaba los api que habia echo en .net

Create a new file /resources/android/xml/network_security_config.xml

Add the following to this file

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

You may add or remove subdomains according to your needs.

Add the following to your config.xml inside of <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>
        <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" />
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />

This worked for me.
I updated widget to this
<widget id="com.kenyatv.live" version="3.4.8" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">

Add xmlns:android=“http://schemas.android.com/apk/res/android

Then added

    <platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:usesCleartextTraffic="true" />
        </edit-config>

Add below snippet inside your config.xml under the platforms tag:

        <access origin="*" />
        <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" />
        </edit-config>
        <allow-navigation href="*" />

Remember to add xmlns:android=“http://schemas.android.com/apk/res/android” attribute in edit-config tag or else it gives error for android platform>=8.

1 Like

for those who use capacitor this answer resolves however you need to use the following command: ionic capacitor run android --livereload --external

1 Like

Lots of suggestion here, regarding lots of problem that leads to the same error i.e. ERR_CLEARTEXT_NOT_PERMITTED .
If you are facing this issue when trying to connect to an api hosted on http rather than https, you are likely to face this error.
for that do these 2 things (assuming ionic4, cordova - 5.4.X)

edit the resources\android\xml\network_security_config.xml like this…

<?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">localhost</domain>
        <domain includeSubdomains="true">dev.somename.com</domain>
        <!-- note this is without http -->
    </domain-config>
</network-security-config>

add this to your config.xml file…

<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:usesCleartextTraffic="true" /> <!-- this is the new line to be added -->
            <application android:networkSecurityConfig="@xml/network_security_config" />
        </edit-config>
      <!-- other config goes here -->
</platform>

after this you should be able to call apis from your http:/dev.somename.com/api/vX/anyurl/

Please Note : above configuration is only needed for http, it should work for https without these configuration as well…try hitting this https://swapi.co/api/films/ from your application.

for more detail description of this refer to this Stackoverflow Discussion. and this particular answer

1 Like

Thanks, it worked for me. :smiling_face_with_three_hearts: :heart_eyes:

just run this command :

ionic cordova run android -l --ssl

Thank you so much! It works on Android 9 and 10!

Have you got the solution for same?

Thanks.
1- does network_security_config.xml already exist or does it need to be created? Does matter where?

2- in Config.xml does usesCleartextTraffic=“true” needed? I thought it was turned on by default. Its more if users want to turn it off?

Thanks for your help.

  1. network_security_config.xml is created itself in resources/android/xml, when you add android as a platform for the application
  2. yes the userCleartextTraffic = “true” is given by default just verify if it is like this or not.