Android平台下奔溃Crash和无响应ANR日志抓取分析

一、使用AndroidStudio

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

AS下载链接

二、使用adb shell dumpsys dropbox命令获取

#!/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}"

三、使用adb+logcat获取

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

Android平台下奔溃Crash和无响应ANR日志抓取分析_第1张图片

四、获取无响应ANR的日志

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

五、常见的异常汇总

NullPointerException:指针为空异常

java.lang.NullPointerException: Attempt to invoke virtual method ‘…’ on a null object reference
ClassCastException:类型转换异常

java.lang.ClassCastException: … cannot be cast to …
IllegalArgumentException:非法参数异常

java.lang.IllegalArgumentException: … is not a valid argument
IllegalStateException:非法状态异常

java.lang.IllegalStateException: … is not in a valid state
IndexOutOfBoundsException:越界异常

java.lang.IndexOutOfBoundsException: Index … out of bounds for length …
OutOfMemoryError:内存溢出错误

java.lang.OutOfMemoryError: Failed to allocate a … byte allocation with … free bytes and …MB until OOM, target footprint …MB, growth limit …MB
NoSuchMethodError:方法不存在错误

java.lang.NoSuchMethodError: … method not found
ArithmeticException:算术异常

java.lang.ArithmeticException: … / by zero
SecurityException:安全异常

java.lang.SecurityException: … not allowed to perform operation
NetworkOnMainThreadException:主线程网络异常

android.os.NetworkOnMainThreadException
InflateException:布局解析异常

android.view.InflateException: Binary XML file line #…: Error inflating class …
ResourcesNotFoundException:资源未找到异常

android.content.res.Resources$NotFoundException: Resource ID #… not found
SQLiteDatabaseLockedException:SQLite数据库锁定异常

android.database.sqlite.SQLiteDatabaseLockedException: database is locked
SQLiteException:SQLite数据库异常

android.database.sqlite.SQLiteException: … error code …
StaleDataException:数据过期异常

android.database.StaleDataException: Attempted to access a cursor after it has been closed.
VerificationError:验证错误

java.lang.VerifyError: … access … from incompatible class …
AssertionError:断言错误

java.lang.AssertionError: … assertion failed
NoSuchAlgorithmException:加密算法不存在异常

java.security.NoSuchAlgorithmException: … algorithm not available
SocketException:Socket异常

java.net.SocketException: … failed: ECONNREFUSED (Connection refused)
SSLException:SSL异常

javax.net.ssl.SSLException: … SSL handshake aborted
FileNotFoundException:文件未找到异常

java.io.FileNotFoundException: … (No such file or directory)
IOException:IO异常

java.io.IOException: … (Connection timed out)
ParseException:解析异常

java.text.ParseException: Unparseable date: “…”
JSONException:JSON解析异常

org.json.JSONException: … at character …
SAXException:SAX解析异常

org.xml.sax.SAXException: … at line …
NumberFormatException:数字格式化异常

java.lang.NumberFormatException: For input string: “…”
IllegalStateException:线程状态异常

java.lang.IllegalStateException: Cannot execute task: the task is already running.
ConcurrentModificationException:并发修改异常

java.util.ConcurrentModificationException: … (java.util.ConcurrentModificationException)
UnsupportedOperationException:不支持的操作异常

java.lang.UnsupportedOperationException: … not supported
InterruptedException:线程中断异常

java.lang.InterruptedException: sleep interrupted
RuntimePermission:权限异常

java.lang.RuntimePermission: … permission required
AuthenticationException:认证异常

org.apache.http.client.ClientProtocolException: … (authentication challenge)
FileNotFoundException:未找到文件异常

java.io.FileNotFoundException: … File not found.
UnsupportedOperationException:不支持的操作异常

java.lang.UnsupportedOperationException: … not supported
EOFException:文件结尾异常

java.io.EOFException: … end of file reached
ConnectException:连接异常

java.net.ConnectException: … Connection refused
SocketTimeoutException:Socket超时异常

java.net.SocketTimeoutException: … Read timed out
JNIException:Java本机接口异常

java.lang.reflect.InvocationTargetException: JNI Exception: …
NoSuchProviderException:提供程序不存在异常

java.security.NoSuchProviderException: Provider … not found
Surface.OutOfResourcesException:Surface资源耗尽异常

android.view.Surface$OutOfResourcesException: … (Surface with no valid EGLContext)
WindowManager.BadTokenException:无效的Window Token异常

android.view.WindowManager$BadTokenException: … is not valid; is your activity running?
TimeoutException:超时异常

java.util.concurrent.TimeoutException: … timeout
SSLHandshakeException:SSL握手异常

javax.net.ssl.SSLHandshakeException: … SSL handshake aborted
SAXParseException:SAX解析异常

org.xml.sax.SAXParseException: … at line …
IllegalStateException:未知的Bundle标记异常

java.lang.IllegalStateException: Unknown Bundle Marker at position …: …
IllegalArgumentException:传递了错误的方位坐标

java.lang.IllegalArgumentException: Point (?, ?) must be in the range ? <= x <= ? and ? <= y <= ?
SQLiteReadOnlyDatabaseException:SQLite只读数据库异常

android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write to a readonly database
SQLException:SQL异常

java.sql.SQLException: … SQL exception
ZipException:压缩文件异常

java.util.zip.ZipException: … Not in GZIP format
DifferentKeyException:与此密钥不相关的密钥异常

java.security.spec.InvalidKeySpecException: Inappropriate key specification: Different key pair generated for given keyUsageInfo

六、参考链接

50个Android开发中常见的异常崩溃情况

Android崩溃日志获取方式

你可能感兴趣的:(Android开发,android)