解决安卓手机无法使用Charles抓包

本文介绍了在Android 7.0及以上版本系统中,由于安全配置导致Charles无法正常抓包的问题及其解决方法。通过创建并配置network_security_config.xml文件,允许应用信任Charles的根证书,并在反编译、打包、签名apk后解决问题。同时,文中列举了在处理过程中可能遇到的错误及解决策略,包括重新签名、检查配置文件等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一:背景及表现
背景:安卓7.0及以上系统无法使用Charles抓包
问题表现:
1.连接代理wifi后无法访问网络
2.抓包数据接口都是 unkown
3.查看接口详细信息详情,其中包含:You may need to configure your browser or application to trust the Charles Root Certificate. See SSL Proxying in the Help menu.

二.问题原因
见官方文档:https://www.charlesproxy.com/documentation/using-charles/ssl-certificates/
在这里插入图片描述
关于此配置文件讲解:
https://developer.android.com/training/articles/security-config?hl=zh-cn

三、解决办法
1.将apk反编译,反编译后的目录结构:
在这里插入图片描述

2.在反编译处理的文件夹目录res/xml/中新建network_security_config.xml,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" overridePins="true" />
            <certificates src="user" overridePins="true" />
        </trust-anchors>
    </base-config>
</network-security-config>

3.文件夹根目录下修改AndroidManifest.xml
在<application末尾加入以下内容,与之前的内容空格隔开:

android:networkSecurityConfig="@xml/network_security_config"

3.重新编译以上整个文件夹,打出新的example.apk
4.签名example.apk
5.安装example.apk
6.装上新打包的apk就可以啦

【参考资料】
详细的反编译、打包、签名过程参考:
https://blog.51cto.com/u_15328720/3391423

【命令】
反编译:

java -jar apktool.jar d hello-release.apk

打包:

java -jar apktool.jar b hello-release  -o hello-debug.apk

生成密钥文件:

keytool -genkey -alias demo.keystore -keyalg RSA -validity 40000 -keystore demo.keystore

签名apk:

jarsigner -verbose -keystore demo.keystore hello-debug.apk demo.keystore

踩坑记录:
【问题一】:重新打包之后,安装报错:

Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed to collect certificates from /data/app/vmdl290988339.tmp/base.apk: Attempt to get length of null array]

【原因】:没有重新签名
【解决办法】:生成keystore文件后签名,重新安装

【问题二】:重新打包之后抓包还是:You may need to configure …
【原因】:network_security_config.xml配置文件问题,
如:漏了
解决办法:补充配置文件,并重新打包安装

【问题三】:新版本重新打包安装报错:

Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package hello-debug.apk signatures do not match previously installed version; ignoring!]

【原因】:打新包时又重新生成了签名文件,与旧包的签名文件不一致
【解决办法1】:卸载手机上的旧包重新安装
【解决办法2】:使用旧的签名文件重新签名

【问题四】在安卓11系统上安卓失败

Failed parse during installPackageLI: Targeting R+ (version 30 and above) requires the resources.arsc of installed APKs to be stored uncompressed and aligned on a 4-byte boundary]

【解决办法】待补充。。。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值