0
点赞
收藏
分享

微信扫一扫

java.net.UnknownServiceException: CLEARTEXT communication to * not permitted by network

_阿瑶 2022-06-12 阅读 12


在Android O 升 P (8.0升9.0)的时候,会报以下异常

java.net.UnknownServiceException: CLEARTEXT communication to * not permitted by network

因为 Android P 是默认禁止访问http的API的。

解决办法:

1,使用https

2,暂时先绕过HTTP限制

  • 在res文件夹下创建xml目录,新建network_security_config.xml文件,名字随意
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
  • 在AndroidManifest.xml的Application中添加配置引用
<application
..
android:networkSecurityConfig="@xml/network_security_config"
... >

绕过只是暂时的,因为有些迁移也是需要时间的,还是尽早适配为好,而且现在适配Android Q也必须提上日程了,毕竟Q的适配相对强制性。



​​Android 9.0http适配原理​​

​​Android 10.0 适配最佳指南​​




举报

相关推荐

0 条评论