How to resolve ERR_CLEARTEXT_NOT_PERMITTED error in Xamarin. It quite annoying. I mean this error as shown below.

Xybernetics Xamarin Error Message ERR_CLEARTEXT_NOT_PERMITTED Error

The main driver behind this error is that it is preventing the app to transmit and store data that should be encrypted. This feature was added starting with Android 9 (API level 28), cleartext support is disabled by default, and hence you will get this error message when you transmit data from the app.

Essentially, you have 3-ish options to remediate this issue. The 4th option is if you have a sanbox parameter.

OPTION #1
Try using the “https://” instead of “http://”.
Note that in htttp, there is no data encryption implemented, while in the https conenction, the data are all encrypted with encryption algorithm.
If the site you are accessing does not support https, then move on to OPTION #2

OPTION #2
Add this configuration XML file in the following folder, res/xml/network_security_config.xml

Xybernetics XamarinAdd network_security_config File ERR_CLEARTEXT_NOT_PERMITTED Error


www.xybernetics.com {THIS COULD BE ANY URL THAT YOU WANT TO PERMIT CLEARTEXT TRANSMISSION}

Add the parameter “android:networkSecurityConfig=”@xml/network_security_config” as shown below.
For example if your, AndroidManifest.xml looks like shown below, add the network security configuration file as shown below.

OPTION #3
Add the security parameter “android:usesCleartextTraffic=”true” as shonwn below.
For example if your, AndroidManifest.xml looks like shown below, add the network security configuration parameter as shown below.
Note that OPTION #3 is less secure than OPTION #2

You can find the AndroidManifest.xml file as shown in the folder below.

Xybernetics Xamarin Modify Manifest XML File ERR_CLEARTEXT_NOT_PERMITTED Error - AndroidManifest.xml

OPTION #4
This is only applicable if you have a sandbox parameter.
Reduce the sandbox version to 1.
The higher the sandbox version number, the higher the level of security. Its default value is 1; you can also set it to 2. Setting this attribute to 2 switches the app to a different SELinux sandbox. The following restrictions apply to a level 2 sandbox:
The default value of usesCleartextTraffic in the Network Security Config is false.

You can find the AndroidManifest.xml file as shown in the folder below.

Xybernetics Xamarin  Location Of Manifest XML File ERR_CLEARTEXT_NOT_PERMITTED Error - AndroidManifest.xml

Reference

Leave a reply

Your email address will not be published. Required fields are marked *