Thudner
Thudner

Reputation: 1169

CLEARTEXT communication not permitted by network security policy working on my mobile

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.

Upvotes: 74

Views: 94598

Answers (3)

Mohd Asif Ahmed
Mohd Asif Ahmed

Reputation: 2170

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.

Upvotes: 141

harry
harry

Reputation: 261

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">

Upvotes: 4

Stepan Nikulenko
Stepan Nikulenko

Reputation: 653

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>

Upvotes: 36

Related Questions