Android(安卓)9 使用okhttp3报错 CLEARTEXT communication to XXXXXXXX not permitted by network security polic
16lz
2021-01-26
Android 9 使用okhttp3报错 CLEARTEXT communication to XXXXXXXX not permitted by network security policy
问题原因:
应用官方的说明:在 Android 6.0 中,我们取消了对 Apache HTTP 客户端的支持。 从 Android 9 开始,默认情况下该内容库已从 bootclasspath 中移除且不可用于应用。且Android 9 限制了明文流量的网络请求,非加密的流量请求都会被系统禁止掉。
解决方案1:
将http转换成https
解决方案2:
在res目录下新建xml文件夹,文件夹中新建文件network_security_config.xml,文件内容如下
<network-security-config> <base-config cleartextTrafficPermitted="true" />network-security-config>
在AndroidManifest.xml文件中,Application标签下添加如下属性:
android:networkSecurityConfig="@xml/network_security_config"
更多相关文章
- android编译系统(一):GUN Make简介
- android studio 3.2---NDK配置
- Android清单文件中相关属性含义(Provider)
- 自定义控件SettingItemView
- 新建Android项目的时候,选择SDK的区别
- Android(安卓)NDK开发起步Hello Jni
- android使用html+javascript来制作页面
- android中创建XML