
最近很多同事反馈使用Charles抓包出现了很多unknown的问题,现象如下图

查看右侧的原因,给出的结果是这样的

这里将讲解如何解决这个问题,但是开始阅读之前,请确认符合如下的条件
好的,开始了。
在应用xml目录下新建一个名为network_security_config.xml,内容为
1 2 3 4 5 6 7 8 | <network-security-config> <debug-overrides> <trust-anchors> <!-- Trust user added CAs while debuggable only --> <certificates src="user" /> </trust-anchors> </debug-overrides> </network-security-config> |
|---|
上面的代码仅仅在debug编译包,信任用户添加的CA证书
在AndroidManifest Application节点增加属性
1 2 3 4 5 6 7 | <?xml version="1.0" encoding="utf-8"?> <manifest ... > <application android:networkSecurityConfig="@xml/network_security_config" ... > ... </application> </manifest> |
|---|
建议重启应用,就能解决问题了。
考虑到安全问题,上面的实现