61

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.

Rahul Gaur
  • 1,661
  • 1
  • 13
  • 29
Thudner
  • 1,043
  • 1
  • 7
  • 14

4 Answers4

112

If you use http instead of https in your url, add this line to AndroidManifest.xml in the <application> tag.

android:usesCleartextTraffic="true"

This should solve your problem.

Mohd Asif Ahmed
  • 1,880
  • 2
  • 15
  • 29
32

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>
JJD
  • 50,076
  • 60
  • 203
  • 339
1

work for me! If you use Http instead of Https in your api url, then
just add => android:usesCleartextTraffic="true" in AndroidManifest.xml in tag.

 <application
    android:allowBackup="true"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:requestLegacyExternalStorage="true"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    tools:targetApi="31"
    android:usesCleartextTraffic="true">
harry
  • 171
  • 1
  • 4
0

android:usesCleartextTraffic="true"

just put this line in your Androidmanifest.xml in <application tag