-
Notifications
You must be signed in to change notification settings - Fork 347
0x00 QuickStart_zh
- 首先确认你的项目是否兼容java8,因为AndroidGodEye使用了java8的语法
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
- 其次你的项目需要迁移至androidx,从版本3.1.3开始AndroidGodEye迁移到了androidx,如果你的项目没有使用androidx,那么只能使用3.1.2及以下版本
在需要的Module的build.gradle
中添加
dependencies {
// 核心模块,必须依赖
implementation 'cn.hikyson.godeye:godeye-core:VERSION_NAME'
// Debug包配置Debug看板
debugImplementation 'cn.hikyson.godeye:godeye-monitor:VERSION_NAME'
// Release包不需要监控看板
releaseImplementation 'cn.hikyson.godeye:godeye-monitor-no-op:VERSION_NAME'
// 额外依赖,如果项目使用OkHttp作为网络请求可以用这个库完成网络监控
implementation 'cn.hikyson.godeye:godeye-okhttp:VERSION_NAME'
// 额外依赖,添加此依赖可以完成Crash监控,如果不依赖则无法监控Crash(安装了也不会生效)
implementation 'cn.hikyson.godeye:godeye-xcrash:VERSION_NAME'
}
VERSION_NAME参考 Github release
在Root Project的build.gradle
中添加
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "cn.hikyson.methodcanary:plugin:PLUGIN_VERSION_NAME"
}
}
PLUGIN_VERSION_NAME参考 MethodCanary github release
在Application Module Project('com.android.application'
)的build.gradle
中添加
apply plugin: 'cn.hikyson.methodcanary.plugin'
在项目根目录下新建js文件:AndroidGodEye-MethodCanary.js
用于配置MethodCanary的插桩逻辑,内容样例如下:
function isInclude(classInfo,methodInfo){
return classInfo.name.startsWith('cn/hikyson/godeye/sample')
}
如何配置AndroidGodEye-MethodCanary.js
Application中初始化:
GodEye.instance().init(this);
模块安装,GodEye类是AndroidGodEye的核心类,所有模块由它提供。
使用GodEye.instance().install(GodEyeConfig);
进行安装,建议在Application onCreate中:
if (ProcessUtils.isMainProcess(this)) {//install in main process
GodEye.instance().install(GodEyeConfig.fromAssets("assets path"));
}
install方法可以重复调用,每次调用会安装还未安装的模块
GodEyeConfig
有几种构建方式
- (一般使用方式)从XML类型assets目录安装
GodEyeConfig.fromAssets("assets path")
- 从XML类型的InputStream安装
GodEyeConfig.fromInputStream(InputStream)
- 默认配置
GodEyeConfig.defaultConfig()
XML样例:install.config
Uninstall方法会将目前已经安装的模块全部卸载,一般不需要调用
// 卸载已经安装的所有模块
GodEye.instance().uninstall();
GodEyeMonitor类是AndroidGodEye的性能可视化面板的主要类,用来开始或者停止性能可视化面板的监控。
开启性能可视化面板:
GodEyeMonitor.work(context)
GodEyeMonitor.shutDown()
usb连上你的手机,接下来可以开始运行你的项目了!
在AndroidStudio中安装AndroidGodEye插件,在AndroidStudio plugin中直接搜索AndroidGodEye即可,安装完之后会在工具栏中出现AndroidGodEye的icon,点击即可在浏览器中打开性能监控面板。
完成,你现在可以在Debug看板中看到你的App的性能了