CLEARTEXT communication to * not permitted by network

image.png

原因是Android P系统限制了明文流量的网络请求,之下的版本没有影响,所以okhttp3会抛出该异常。

解决方法(亲测有效):
在res目录下新建xml文件夹,文件夹里面创建network_security_config.xml 文件;
文件内容



    

然后在 AndroidManifest.xml 的application 标签加上

 

或者application 加这个属性 android:usesCleartextTraffic="true"

 

你可能感兴趣的:(CLEARTEXT communication to * not permitted by network)