ERR_CLEARTEXT_NOT_PERMITTED in debug app on Android

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

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!