android 10 开发者适配

android 10 开发者适配

1. 编译工具版本升级

compileSdkVersion 29			// 编译Sdk版本调整到android 10, api 29
buildToolsVersion "29.0.2"		// 构建工具版本调整到android 10, 29.0.2

targetSdkVersion 29				// 目标编译版本调整到android 10, api 29

2. 网络请求报错处理

这里的内容参考(https://blog.csdn.net/qq_18620851/article/details/80617549), 特注明出处;

错误信息: CLEARTEXT communication to 39.104.75.19 not permitted by network security policy
错误原因: Android P 限制了明文网络请求,非加密的请求都会被拦截掉, 意思就是, 如果使用的是http方式请求, 会被拦截掉, 如果是https则不会, 这里okhttp框架做了处理, 如果在android p后使用http请求, 会抛出异常: CLEARTEXT communication to 39.104.75.19 not permitted by network security policy;

处理方法:
在 res 下新建一个 xml 目录,然后创建一个名为:network_security_config.xml 文件, 内容如下:

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

截图:
网络请求报错处理

发布了25 篇原创文章 · 获赞 2 · 访问量 1501

猜你喜欢

转载自blog.csdn.net/geaosu2/article/details/103700100