Livereload ERR_CLEARTEXT_NOT_PERMITTED

When using:
ionic cordova run android --livereload
I get the following error on my device:
Zrzut%20ekranu%20z%202019-05-09%2011-19-37

so the problem is the ERR_CLEARTEXT_NOT_PERMITTED . I have try it to add to my manifest but unfortunately the manifest is overwritten after
ionic cordova run android --livereload

2 Likes

Just happen the same to me. Add this to config.xml


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

I’ve tried the config.xml version, but couldn’t get a result.

Then i’ve read solutions about
android:networkSecurityConfig="@xml/network_security_config"

In the config.xml we automatically get an edit-config property which puts the network_security_config.xml into equation.

When we look at this xml property’s source file we see the cleartextTrafficPermitted="true" and as a sub-property <domain>localhost</domain>.

So i’ve added
<domain>PORT_MY_APP_RUNNING_ON</domain>
(i.e. <domain>123.456.7.8</domain> )

2 Likes

@IO-zlu I have tried your solution (because, like you I had no results with the config.xml) but my changes in the network_security_config.xml are overwritten and it does not work.

How did you do to prevent this ?

I suppose you’re trying to change the target network xml.

You have to change the source file. You can find the path of the source from config.xml.

Edit:
Didn’t have my computer with me when i was writing this reply.
I’m appending path to source file.

resources/android/xml/network_security_config.xml

2 Likes

Ha, yes :frowning: did not see that.
Thanks… it is working

Same problem, but not fixed with
resources/android/xml/network_security_config.xml
change… still overwritten somehow

2 Likes

I formatted my pc, install latest ionic. Now non of the solutions above works. Any ideas?
Edit: nevermind, i solve it like IO-zlu suggested

1 Like

I had the same problem. The solution is to modify the file “config.xml”:
Before I had:

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

I commented on both lines and left only the following code:

<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>

and it works well :slight_smile:

1 Like

Doesn’t work for me :frowning: Any idea or solution?

1 Like

Use the below command to livereload, it will work
ionic cordova run android --device -l --ssl --debug

1 Like

Same Problem help me on this

Maybe you can try some of these things:

  1. Check your 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:networkSecurityConfig="@xml/network_security_config" />
            <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" />
        <allow-navigation href="*" />
  1. You enter all domains, localhost, webservices / api, upload url, etc at resources/android/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain>localhost</domain>
        <domain>api.example.id</domain>
        <domain>www.youtube.com</domain>
    </domain-config>
</network-security-config>
  1. You can clean and reload the Android Platform & AndroidManifest.xml

cordova clean android

1 Like

same problem any solutions ??

this work <domain>PORT_MY_APP_RUNNING_ON</domain>
(i.e. <domain>123.456.7.890</domain> )

I’m unable to add
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge"
on config.xml, because at every build that line is removed (I don’t know why)

1 Like

It’ll work fine if you add the config to network_security_config.xml in the resources/android/xml folder.

change it like,

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
    	<domain includeSubdomains="true">localhost</domain>
    	<domain includeSubdomains="true">Your server ip or domain address</domain>
    </domain-config>
</network-security-config>

remember not to include http:// and port number in it.

For Eg: if your server is running at http://123.456.789.00:8080, then the config should be,

<domain includeSubdomains="true">123.456.789.00</domain>

1 Like

this works for me! thanks. my env: ionic 5.2.3