Android崩溃日志获取方式

在日常测试安卓的app时,经常会遇到崩溃问题,于是经常需要获取崩溃日志。

一、通过adb logcat获取

# 清除日志,日志内容很多,对于能毕现的日志,可以先清除后重新获取adb logcat -c# 然后再次运行崩溃操作,再抓取日志# 存储日志到当前目录下的 carsh.log 中adb logcat -d *:W > crash.log # W指的是警告以上日志# 这个日志文件包含了所有打印的日志,需要自己筛选下崩溃日志,比如搜索 begin、crash、Exception# 为了更精确的筛选日志,可以加入筛选条件adb logcat -d *:W grep “包名” >crash.log

二、通过Android Studio

在logcat中查看实时日志,需要选择连接的手机和应用包名

三、通过adb shell dumpsys dropbox命令获取

封装成shell脚本,可以快速打印最新的崩溃日志#!/bin/bash# path="/data/system/dropbox"   # 在手机这个目录下存储了崩溃日志newest_time=$(adb shell dumpsys dropbox | grep 'data_app_crash' | awk 'END {print $1,$2}')adb shell dumpsys dropbox --print ${newest_time}# echo -e "时间是:${newest_time}"

四、获取ANR日志​​​​​​​

# 在/data/anr/目录下存储所有了ANR日志(Application Not Responding)adb pull /data/anr/ ~/Downloads

常见异常​​​​​​​

NullPointerException-空指针引用异常
ClassCastException-类型强制转换异常。
IllegalArgumentException-传递非法参数异常。
ArithmeticException-算术运算异常
ArrayStoreException-向数组中存放与声明类型不兼容对象异常
IndexOutOfBoundsException-下标越界异常
NegativeArraySizeException-创建一个大小为负数的数组错误异常
NumberFormatException-数字格式异常
SecurityException-安全异常
UnsupportedOperationException-不支持的操作异常

欢迎关注我的公众号【测试开发备忘录】,一起沟通交流~​​​ 

猜你喜欢

转载自blog.csdn.net/hashsabr/article/details/129480979
今日推荐