前言
-
你的测试团队是否和你抱怨,网络抓包工具不好用,Https抓不到,降低测试效率
-
你:测试环境用http不就好了,测试:那线上呢?你:那用下面方式
- 使用抓包工具,导出证书
- 手机端安装证书
- 设置系统代理
测试:那你教我~
-
之前我写过一篇文章:DebugTools------一个设计开发者支撑工具库中曾提到过关于网络抓包,但是得到反馈说全部都堆在一起了,不太好用,所以这次做了一次升级
-
升级后效果如下

DebugTools功能
- 支持查看最新接口前100条数据
- 支持正序和倒序排序
- 可查看每个接口的Header,请求参数与返回结果
- 支持分享给开发
How To
- Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:
rust
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Step 2. Add the dependency
arduino
dependencies {
implementation "com.github.Peakmain:DebugTools:+"
}
如何使用
一、首先在okHttp中添加拦截器
java
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(new com.peakmain.debug.log.HttpLoggingInterceptor());
二、显示网络抓包工具页面
kotlin
findViewById<TextView>(R.id.tv_name).setOnClickListener {
val clazz = Class.forName("com.peakmain.debug.DebugToolDialogFragment")
val target = clazz.getConstructor().newInstance() as DebugToolDialogFragment
target.show(supportFragmentManager, "debug_tool")
}
三、所有Activity显示悬浮按钮点击显示网络抓包工具
- 可以使用我的另一个第三方库:github.com/Peakmain/Ba... 的SuspensionView
- demo代码如下,在自己的基本Activity中调用下方代码即可
kotlin
fun addSuspensionView(activity: AppCompatActivity) {
val suspensionView = SuspensionView(
activity, com.atour.atourlife.R.drawable.ui_ic_suspension_setting,
56f, 60f, 20f, null, 0
)
activity.addContentView(
suspensionView,
FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
)
)
suspensionView.setSuspensionViewClick {
var clazz: Class<*>? = null
try {
clazz = Class.forName("com.peakmain.debug.DebugToolDialogFragment")
val target: DebugToolDialogFragment =
clazz.getConstructor().newInstance() as DebugToolDialogFragment
target.show(activity.getSupportFragmentManager(), "debug_tool")
} catch (e: Exception) {
throw RuntimeException(e)
}
}
}
Jenkins智能控制开关
- Android在项目的build.gradle(一般都是app/build.gradle),利用project.property获取属性,比如我这里属性名是IS_LOG_CONSONLE_ENABLE
ini
def releaseLogConsoleEnable = project.property('IS_LOG_CONSONLE_ENABLE')
- buildTypes中通过buildConfigField方法,将属性添加BuildConfig
arduino
buildTypes {
release {
buildConfigField "boolean", "releaseLogConsoleEnable", releaseLogConsoleEnable
}
debug {
buildConfigField "boolean", "releaseLogConsoleEnable", releaseLogConsoleEnable
}
}
- 显示开关按钮的地方,添加代码开关
scss
if(BuildConfig.releaseLogConsoleEnable) {
addSuspensionView(this);
}
至此Android相关代码配置完成,接下来是Jenkins 4. Jenkins添加选项设置属性为IS_LOG_CONSONLE_ENABLE

- Jenkins gradle配置代码-PIS_LOG_CONSONLE_ENABLE=$IS_LOG_CONSONLE_ENABLE
bash
./gradlew -Dgradle.user.home=$GRADLE_HOME clean assemble$buildType -b ${WORKSPACE}/app/build.gradle -PIS_LOG_CONSONLE_ENABLE=$IS_LOG_CONSONLE_ENABLE
最后
- 上述便是《Android网络抓包工具升级与Jenkins智能控制开关》的全部内容,大家如果有什么问题,可以在下方留言哦
- 如果你觉得文章和项目对你有点帮助,欢迎点赞来踩哦,你的star是我的动力