Problem Description:

The following error occurs on Android9.0(SDK version 28), not on Android9.0(SDK version 28), using the network framework is OKHttp

Java.net.UnknownServiceException: CLEARTEXT communication to xxx.xxx.com (domain name) is not permitted by the network security policy

Solutions:

1. Change the APP to HTTPS request (this requires background assistance and HTTPS certificate, which is easy to solve)

2. TargetSdkVersion drops to 27 or below

3, the application in the listing file node add < application android: usesCleartextTraffic = “true” > original default is true, but change the default value to false in android 9.0, Therefore, manually setting the configuration to true resolves the problem of restricted plaintext transmission

4. Change the network security configuration

Create an XML folder and create network_security_config.xml

<? xml version="1.0" encoding="utf-8"? ><network-security-config> <base-config cleartextTrafficPermitted="true" /></network-security-config>Copy the code

Under the listing file application node add < application android: networkSecurityConfig = “@ XML/network_security_config” >

Expanded description:

In order to protect user data and devices, Google will require encrypted connections to be used by default for the next generation of Android applications. This means that Android P will prohibit apps from using all unencrypted connections. Therefore, Android devices running Android P will not be able to receive or send traffic with explicit codes in the future, and will need to use the next generation Transport Layer Security protocol, while Android Nougat and Oreo will not be affected.