腾讯 Bugly 和 CrashHandler 冲突,不上传日志
来源:互联网 发布:神回复知乎 编辑:程序博客网 时间:2024/06/03 21:40
简单介绍
CrashHandler 是继承 UncaughtExceptionHandler 类来处理 app 崩溃,自由度比较大
可以收集日志信息保存到本地,上传网络,并重启应用.可以说是除了三方的异常上报工具,
开发者使用最多的一种方式
Bugly 是腾讯公司为移动开发者开放的服务之一,这里主要指 Crash 监控、崩溃分析等质量跟踪服务。
问题描述
CrashHandler 是 app 以前就有的错误收集机制,但是其日志功能并不是很强大.因此引入 Bugly 的
异常上报功能.但是集成好之后 调用CrashReport.testJavaCrash();
测试
一直不上传日志到控制台
解决办法
解决办法在初始化顺序
//异常日志捕获CrashHandler.getInstance().init(this);//腾讯bugly,需放在 CrashHandler 后面,否则无法上传信息initBugly();private void initBugly() { CrashReport.initCrashReport(getApplicationContext(), "appid", true);}
问题分析
这里对问题产生原因做一些探究
首先我们把问题还原
initBugly(); //异常日志捕获 CrashHandler.getInstance().init(this);
这样运行后 调用CrashReport.testJavaCrash();
测试, 结果日志不上传
接下来看 CrashHandler 的 init() 方法,
public void init(Context context) { mContext = context; mDefaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); //设置当前的处理类为默认异常处理器 // Thread.setDefaultUncaughtExceptionHandler(this);}
我们把最后一行注释掉,结果日志能正常上传
这里有产生 第一个猜想 :是这个设置默认异常捕获类的代码引起的. 当然实际上我们不能注释,
否则 CrashHandler 就作废了
接下来 第二个猜想 :是不是在实际异常处理中导致的 Bugly 失效呢?
//取消注释 Thread.setDefaultUncaughtExceptionHandler(this);//注释掉所有异常处理方法 @Override public void uncaughtException(Thread thread, Throwable ex) {// boolean isHandle = handleException(ex);// if (!isHandle) {// if (mDefaultUncaughtExceptionHandler != null) {// //如果程序员没有处理异常,则交给系统的异常处理器// mDefaultUncaughtExceptionHandler.uncaughtException(thread, ex);// } else {// //如果默认异常处理器为空,则需要退出程序。// exitSystem();// }// } }
运行程序测试,结果日志不上传
到这里基本确定产生冲突的原因是
Thread.setDefaultUncaughtExceptionHandler(this);
但是这个方法的源码
public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler handler) { Thread.defaultUncaughtHandler = handler;}
以及 UncaughtExceptionHandler 源码
/** * Implemented by objects that want to handle cases where a thread is being * terminated by an uncaught exception. Upon such termination, the handler * is notified of the terminating thread and causal exception. If there is * no explicit handler set then the thread's group is the default handler. */ public static interface UncaughtExceptionHandler { /** * The thread is being terminated by an uncaught exception. Further * exceptions thrown in this method are prevent the remainder of the * method from executing, but are otherwise ignored. * * @param thread the thread that has an uncaught exception * @param ex the exception that was thrown */ void uncaughtException(Thread thread, Throwable ex); }
都未能给予我更深入探索的入口,到这里也只能停止了.
如果哪位小伙伴有新的分析思路还望能留言在此,谢谢.
阅读全文
0 0
- 腾讯 Bugly 和 CrashHandler 冲突,不上传日志
- 腾讯云SDK 与 腾讯Bugly集成冲突记录
- 上传程序crash的日志------bugly
- 腾讯bugly
- 腾讯bugly
- 三、腾讯统计和bugly追踪集成
- Android集成腾讯Bugly和简单使用
- 实现bugly仅在release下上传错误日志和mapping文件
- 腾讯Bugly,简单实用的崩溃日志收集
- 腾讯bugly 的crash 上报和umeng的比较(crash监测工具对比,bugly胜)
- Android 腾讯Bugly——异常上报和应用更新
- 腾讯Bugly的使用
- 腾讯Bugly设置
- 腾讯Bugly快速集成
- 腾讯Bugly的使用
- 腾讯Bugly的使用
- 腾讯bugly热更新
- 腾讯bugly捕获异常
- 【Python】Python3 List sort()方法
- 素数筛法
- stm32 SD卡
- 在Xshell中使用sz、rz进行本机和远程主机(或虚拟机)之间文件的传输
- MySQL数据库优化的八种方式(经典必看)
- 腾讯 Bugly 和 CrashHandler 冲突,不上传日志
- Ubuntu下Android Studio真机测试解决办法
- java 中Properties类的操作
- Two Subarrays Gym
- R语言数据可视化
- Postman持续集成思路:Xshell实现Windows上传文件到Linux主机
- Spring01---简单配置
- Openacs JavaScript 脚本
- 生成不同类型的验证码类