How to get crash log from android device with adb logcat

When we develop Android application, it’s very important to get the crash log, in this article, I will describe how I get the crash log…

How to get crash log from android device with adb logcat

When we develop Android application, it’s very important to get the crash log, in this article, I will describe how I get the crash log with adb logcat.

Connect device with adb

In my another article, I describe how to connect device with adb, the article is listed below:

How to query sqlite database with adb tool
Today, I am research how to use adb command line tool, I want to query data from sqlite database, for android device or…

Solution 1: Use adb logcat directly

First we can run this command on the terminal directly, like below:adb -s <$ANDROID_SERIAL> logcat -b crash

Solution 2: Use adb shell

We can also use adb shell, after connect to the adb shell, we can use logcat command to get the crash log, the command is like below:$ adb -s adb-816d824e-2lp6Pe._adb-tls-connect._tcp. shell
curtana:/ $ logcat -b crash
--------- beginning of crash
...


logcat command

There are a lot of options for logcat , for me the most important option is how to list the logs for a specific application, which is --pid option, to use this option, we need get the pid for the application.

Get application pid

To get the pid, we can use ps command, for example I can search the pid of chrome like following:curtana:/ $ ps -A | grep chrome                                                                                  
u0_a214        4399    829 1557196 181892 0                   0 S com.android.chrome
u0_a214        4478    829 1833060  53532 0                   0 S com.android.chrome_zygote
u0_i0          4507   4478 1695756 104552 0                   0 S com.android.chrome:sandboxed_process0:org.chromium.content.app.SandboxedProcessService0:0
u0_a214        4522    829 1495976 112800 0                   0 S com.android.chrome:privileged_process0

Show logcat with specific pid

After get the pid, we can use the pid to get the logs with logcat, the pid for chrome is 4399, so the command is like below:curtana:/ $ logcat --pid 4399
--------- beginning of system

If you also an Android Developer, hope this article can help you in your daily work.

Thanks for your reading!