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 in AndroidManifest.xml
also I added android: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.
If your application must support loading plain http:// URLs, you can opt into enabling cleartext traffic by using an AndroidManifest. xml file that includes an android:usesCleartextTraffic="true" application attribute.
you cannot allow cleartext traffic as the default. this is what occurs when you add the cleartext macro to your manifest. you have to remove that line from the manifest and create your own network security config file. in it you will add a list of url's for which your app permits cleartext.
Cleartext is any transmitted or stored information that is not encrypted or meant to be encrypted. When an app communicates with servers using a cleartext network traffic, such as HTTP, it could raise a risk of eavesdropping and tampering of content. If you are using the https, then no worry about this issue.
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
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.
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>
test
manifest):<application android:networkSecurityConfig="@xml/network_security_config" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name=" (...) </application>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With