一、配置依赖
Bugtags SDK已经同步到jcenter 和MavenCentral,在项目的build.grade(项目最外层的,不是在app文件夹里的)设置repositories
添加如下依赖:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.bugtags.library:bugtags-gradle:latest.integration'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
也可以在添加依赖时指定版本,如下:
dependencies {
classpath 'com.bugtags.library:bugtags-gradle:1.0.8'
}
然后配置app里的build.grade如下:
//应用插件
apply plugin: 'com.bugtags.library.plugin'
//自动上传插件
bugtags {
appKey "15fc5037852b635247ef63750c7e9f22" //这里是你的 appKey
appSecret "APP_SECRET" //这里是你的 appSecret,管理员在设置页可以查看
trackingNetworkEnabled true //开启网络请求跟踪功能(企业版)
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.bugtags.library:bugtags-lib:latest.integration'
}
二、添加回调方法
在所有的Activity或者Activity基类中在对应的3个生命周期中添加3个回调方法,如@Override
protected void onResume() {
super.onResume();
Bugtags.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
Bugtags.onPause(this);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Bugtags.onDispatchTouchEvent(this, ev);
return super.dispatchTouchEvent(ev);
}
三、启动SDK
继承Application,在onCreate中初始化Bugtags,添加如下语句:
Bugtags.start("APP_KEY", this, Bugtags.BTGInvocationEventNone);
super.onCreate();