1、创建network_security_config.xml文件,并将其拷贝到应用资源nativeResources\android\res\xml目录下
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>
2、创建AndroidManifest.template.xml文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="你自己的包名">
<!-- 信任用户证书,用于非生产环境抓包 -->
<application android:networkSecurityConfig="@xml/network_security_config">
</application>
</manifest>
3、修改vue.config.js或vite.config.js
const fs = require('fs');
const path = require('path');
const templateFilePath = path.join(__dirname, 'AndroidManifest.template.xml');
const outputFilePath = path.join(__dirname, 'AndroidManifest.xml');
const config = require('./config.js')
// #ifdef APP
// 非生产环境,添加网络安全配置,用于抓包
if(config.env !== 'prod'){
fs.copyFileSync(templateFilePath, outputFilePath);
}else if(fs.existsSync(outputFilePath)){
fs.unlinkSync(outputFilePath)
}
// #endif
4、下载抓包工具Reqable
下载地址:https://reqable.com/zh-CN/download
0 个评论
要回复文章请先登录或注册