Dokit是滴滴推出的一款APP性能分析工具。
APP引入以后的界面。
一.Dokit的接入
官网地址:
didi/DoKit: 一款面向泛前端产品研发全生命周期的效率平台。 (github.com)
1.项目build.gradle添加插件依赖
buildscript {
dependencies {
…
classpath 'io.github.didi.dokit:dokitx-plugin:${lastversion}'
…
}
}
2.主项目模块app增加依赖项build.gradle
plugins {
id 'org.jetbrains.kotlin.android'
id 'com.didi.dokit'
}
dependencies增加dokit库依赖
debugImplementation 'io.github.didi.dokit:dokitx:3.5.0'
releaseImplementation 'io.github.didi.dokit:dokitx-no-op:3.5.0'
增加插件配置项,与android同级
dokitExt {
//通用设置
comm {
//地图经纬度开关
gpsSwitch true
//网络开关
networkSwitch true
//大图开关
bigImgSwitch true
//webView js 抓包
webViewSwitch true
}
}
配置Dokit全局属性
项目gradle.properties中配置全局属性
# dokit全局配置
# 插件开关
DOKIT_PLUGIN_SWITCH=true
# DOKIT读取三方库会和booster冲突 如果你的项目中也集成了booster 建议将开关改成false
DOKIT_THIRD_LIB_SWITCH=true
# 插件日志
DOKIT_LOG_SWITCH=true
# 自定义Webview的全限定名 主要是作用于h5 js抓包和数据mock
DOKIT_WEBVIEW_CLASS_NAME=com/didichuxing/doraemonkit/widget/webview/MyWebView
# dokit 慢函数开关
DOKIT_METHOD_SWITCH=true
# dokit 函数调用栈层级
DOKIT_METHOD_STACK_LEVEL=4
# 0:默认模式 打印函数调用栈 需添加指定入口 默认为application onCreate 和attachBaseContext
# 1:普通模式 运行时打印某个函数的耗时 全局业务代码函数插入
DOKIT_METHOD_STRATEGY=0
3.Dokit初始化处理
//dokit性能监测工具,当前没有平台注册,所以只能手机端本地使用
if (BuildConfig.DEBUG) {
val list = ArrayList<AbstractKit>()
list.add(HttpKit())
list.add(NetworkSwitchKit())
DoKit.Builder(QYApplication.appContext)
.customKits(list)
.build()
}
这些工具小插件需要自己实现。
class HttpKit : AbstractKit() {
override val category: Int
get() = Category.PERFORMANCE
override val name: Int
get() = R.string.network
override val icon: Int
get() = R.mipmap.all_plate_icon
override fun onClickWithReturn(activity: Activity): Boolean {
startUniversalActivity(HttpFragment::class.java,activity,null,true)
return true
}
override fun onAppInit(context: Context?) {
}
}