androidandroid-networking

What difference between "Clear text communication not permitted" problem's solutions


We know that Android Pie doesn't allow Clear text communication. And I found two solutions. All of them work fine. But what is the difference between them? Thanks.

Solution 1:

Manifest:

android:usesCleartextTraffic="true"

Solution 2:

@xml/network_security_config.xml

<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

Manifest:

android:networkSecurityConfig="@xml/network_security_config"


Solution

  • And I found for me two solutions

    Neither are the correct solution: use HTTPS. I expect that Google will increasingly penalize apps that use the solutions that you cite, possibly including a future ban from the Play Store.

    But what difference between them?

    They have the same effect. Network security configuration (your second solution) is far more powerful and flexible. android:usesCleartextTraffic will be ignored on Android 7.0+ if you use network security configuration for anything.