gradle配置
dependencies {//bugly
compile'com.tencent.bugly:crashreport:latest.release' //其中latest.release指代最新Bugly SDK版本号,也可以指定明确的版本号,例如2.1.9
compile'com.tencent.bugly:nativecrashreport:latest.release' //其中latest.release指代最新Bugly NDK版本号,也可以指定明确的版本号,例如3.0
}
defaultConfig {
ndk {
// 设置支持的SO库架构
abiFilters'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
}
}
权限
"android.permission.READ_PHONE_STATE"
"android.permission.INTERNET"
"android.permission.ACCESS_NETWORK_STATE"
"android.permission.ACCESS_WIFI_STATE"
"android.permission.READ_LOGS"
初始化:
private void initBugly() {
Context context = getApplicationContext();
// 获取当前包名
String packageName = context.getPackageName();
// 获取当前进程名
String processName =getProcessName(android.os.Process.myPid());
// 设置是否为上报进程
CrashReport.UserStrategy strategy =new CrashReport.UserStrategy(context);
strategy.setUploadProcess(processName ==null || processName.equals(packageName));
CrashReport.initCrashReport(getApplicationContext(), "518f39243f", true);
}
/**
* 获取进程号对应的进程名
*
* @param pid 进程号
* @return 进程名
*/
private static StringgetProcessName(int pid) {
BufferedReader reader =null;
try {
reader =new BufferedReader(new FileReader("/proc/" + pid +"/cmdline"));
String processName = reader.readLine();
if (!TextUtils.isEmpty(processName)) {
processName = processName.trim();
}
return processName;
}catch (Throwable throwable) {
throwable.printStackTrace();
}finally {
try {
if (reader !=null) {
reader.close();
}
}catch (IOException exception) {
exception.printStackTrace();
}
}
return null;
}
进行测试会引起崩溃可在后台查看
CrashReport.testJavaCrash(); bugly崩溃测试
网友评论