CLEARTEXT communication not permitted by network security policy working on my mobile
Solution 1
If you use Http instead of Https in your api url, then just add this line in AndroidManifest.xml in <application> tag.
android:usesCleartextTraffic="true"
It will solve your problem
Solution 2
I had the same problem with react-native project. I get resolved the issue with this article, putting the domain name of my hosting provider.
- Create
res/xml/network_security_config.xml
with content:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">my-domain-name.com</domain>
</domain-config>
</network-security-config>
- Point to this file from your manifest (for bonus points add it only for the
test
manifest):
<application
android:networkSecurityConfig="@xml/network_security_config"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=" (...)
</application>
Thudner
Updated on July 09, 2022Comments
-
Thudner almost 2 years
I am building an APP, and facing CLEARTEXT communication not permitted by network security policy error on my friend mobile (I am just testing it on anther mobile). of course i am not able to trace the problem as the application is working OK on my mobile (without USB debugging), I download it from google play.
I did all needed to resolve this problem by adding
android:usesCleartextTraffic="true"
to application tag inAndroidManifest.xml
also I addedandroid:networkSecurityConfig="@xml/network_security_config"
my config XML:
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">MY IP</domain> </domain-config> </network-security-config>
Its still not working. I cannot trace the problem on my mobile because its working. Why i am not getting the same error as my friend mobile???
I want it to give me same error on my mobile to be able to trace the problem. I removed all the above options and it still working on my mobile. It was even working before I added any thing as I only discovered the problem after Installed on my friend mobile.
-
Dr Deo over 2 yearsok, but whats the point of introducing such a feature by google except complicate dev life
-
Top-Master about 2 yearsAny way to do this programmatically?