Solve net::ERR_CLEARTEXT_NOT_PERMITTED Error in Android
This error started to appear presumably since android 8 or 9 updates, you can try these simple lines of codes in your android manifest file, remember to place it in the <Application of manifest file
What this line of code do is it approves the use cleartext traffic. So here is the code to fix android ERR_CLEARTEXT_NOT_PERMITTED Error
android:usesCleartextTraffic="true"
This will show API warning, to remove that warning, use the tools ignore code, example:
android:usesCleartextTraffic="true" tools:ignore="UnusedAttribute"
The total code should look like this
<application android:icon="@mipmap/ic_launcher" android:usesCleartextTraffic="true" android:label="@string/app_name" tools:ignore="UnusedAttribute" android:theme="@style/AppTheme"> ... </application>
If this doesn’t fix your error, create a new network_security_config.xml file inside a folder named xml and paste this code in it:
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <base-config cleartextTrafficPermitted="true"> <trust-anchors> <certificates src="system" /> </trust-anchors> </base-config> </network-security-config>
Now in your manifest application tag, add this code
android:networkSecurityConfig="@xml/network_security_config"
Example:
<application android:icon="@mipmap/ic_launcher" android:usesCleartextTraffic="true" android:label="@string/app_name" android:networkSecurityConfig="@xml/network_security_config" tools:ignore="UnusedAttribute" android:theme="@style/AppTheme"> ... </application>