How enable clear text traffic on Android 9

Jorge Guilherme
1 min readSep 24, 2019

The update from Android PIE we come across the error ERR_CLEARTEXT_NOT_PERMITTED. To resolve it is necessary to allow unencrypted traffic. To enable all IPS, follow the steps below.

Resolve on native Android:
Access to app/src/main/res/xml/network_security_config.xml and replace for this code.

<?xml version=”1.0" encoding=”utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted=”true” />
</network-security-config>

After edit file go to AndroidManifests.xml and add:

<application
android:name=".core.App"
android:networkSecurityConfig="@xml/network_security_config"
android:allowBackup="true"
...

Resolve on Ionic:
Access to config.xml and add this code:

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

After change config.xml, go to resources/android/xml/network_security_config.xml and replace for this code:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>

Start an ionic build, after finishing make sure platform/android/app/src/res/xml/network_security_config` is enabled clear text traffic. Must be like the file below:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>

Enable to specific IP:
Replace the file network_security_config.xml (file path mentioned above), by the code below.

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

--

--