Capturing and Analyzing Android App Crash Logs with ADB and Logcat

14 min read Step‑by‑step guide to capture, filter, and interpret Android app crash logs with ADB and Logcat without rooting your device. October 03, 2026 08:00 How to Capture and Analyze Android App Crash Logs Using ADB and Logcat (No Root)

When an app suddenly closes or behaves erratically, the first place to look is the crash log. Android records a detailed stack trace for every unhandled exception, and you can retrieve it with the adb tool and logcat without needing root access. This tutorial walks you through the entire workflow: preparing the device, capturing the log, filtering the relevant lines, and interpreting the output to pinpoint the cause.

Before you start

  • USB cable: Use a good quality data cable; a charging‑only cable will not transmit ADB commands.
  • Computer: Windows, macOS, or Linux with admin rights to install drivers if needed.
  • Battery: Keep the device charged above 50 % to avoid interruptions.
  • Wi‑Fi (optional): If you prefer a wireless connection, you can set up adb over Wi‑Fi after the initial USB setup.

1. Enable Developer Options and USB Debugging

  1. Open Settings on your Android device.
  2. Scroll to About phone (or System → About phone on some OEM skins).
  3. Tap Build number seven times. You’ll see a toast: “You are now a developer!”.
  4. Return to the main Settings page; a new entry Developer options appears.
  5. Enter Developer options and toggle USB debugging ON.
  6. If a prompt appears asking to allow USB debugging from this computer, tap Allow. You can also check “Always allow from this computer” for future sessions.

Why this matters: USB debugging exposes a secure channel that lets adb communicate with the device. Without it, the computer cannot issue logcat commands.

2. Install the Android Debug Bridge (ADB) on Your Computer

  1. Download the Platform‑Tools package for your OS.
  2. Extract the ZIP to a convenient location (e.g., C:\adb on Windows or ~/adb on macOS/Linux).
  3. Add the folder to your system PATH so you can run adb from any terminal.
    • Windows: Control Panel → System → Advanced system settings → Environment Variables → Path → New → browse to the folder.
    • macOS/Linux: Add export PATH=$PATH:~/adb to your ~/.bashrc or ~/.zshrc.
  4. Open a terminal (Command Prompt, PowerShell, Terminal) and verify the installation:
    adb version
    You should see something like Android Debug Bridge version 1.0.41.

Tip: If your computer asks to install a driver (Windows), let it do so. The generic Google USB driver works for most devices.

3. Verify the Connection

  1. Connect the phone via USB.
  2. In the terminal, run:
    adb devices
  3. You should see a line with the device’s serial number and the word device.
    0123456789ABCDEF    device

If you see unauthorized, check the phone for the debugging permission dialog and grant access.

4. Capture a Crash Log

There are two common scenarios: you know which app crashes, or you want to capture any crash that happens while the device is idle.

4.1 Capture a Specific App’s Crash

  1. Identify the app’s package name. You can find it in Settings → Apps, or run:
    adb shell pm list packages | grep -i partial_name
  2. Start logcat filtered to that package and write to a file:
    adb logcat --pid=$(adb shell pidof -s com.example.app) -v threadtime > crash_log.txt
    Explanation: pidof -s returns the process ID of the app; -v threadtime adds timestamps and thread IDs for easier reading.
  3. Reproduce the crash on the device (tap the button that crashes, open a specific screen, etc.).
  4. After the crash, stop the logging by pressing Ctrl + C in the terminal.

4.2 Capture Any Crash on the Device

  1. Run a broad logcat command that records everything but filters for the keyword FATAL EXCEPTION:
    adb logcat *:S AndroidRuntime:E > full_crash.txt
    Explanation: *:S silences all tags, while AndroidRuntime:E keeps only error‑level messages from the runtime, which include stack traces.
  2. Trigger the crash on the device.
  3. Stop the command with Ctrl + C. The file full_crash.txt now contains the full stack trace.

5. Filter and Save the Relevant Portion

Logcat files can be large. Use simple command‑line tools to isolate the exact stack trace.

  1. Open the log file in a text editor (VS Code, Notepad++, nano, etc.). Look for lines that start with E/AndroidRuntime or contain FATAL EXCEPTION.
  2. Alternatively, run a grep command (Linux/macOS) or findstr (Windows):
    grep -A 20 "FATAL EXCEPTION" crash_log.txt > filtered.txt
    This extracts the crash line and the next 20 lines (usually the full stack).

Now you have a concise file (filtered.txt) that you can share with developers or keep for personal reference.

6. Analyze the Stack Trace

Understanding the stack trace is the key to fixing the problem. Here’s a typical Android crash snippet:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.app, PID: 12345
    java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
        at com.example.app.ui.MainActivity.onCreate(MainActivity.java:45)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1300)
        ... 9 more

Break it down:

  • Exception type – NullPointerException tells you a null reference was accessed.
  • Message – Shows which method call caused the null reference.
  • Location – com.example.app.ui.MainActivity.onCreate(MainActivity.java:45) points to the exact file and line number.
  • Thread – main indicates the UI thread; crashes on background threads may have different implications.

If you have the app’s source code (open‑source apps, your own project), open the indicated file and line. If you don’t have source, you can still infer the problematic area by searching the package name on the Play Store or GitHub.

Common Patterns and What They Mean

PatternTypical CauseQuick Fix
java.lang.IllegalStateException: Fragment ... not attached to a contextAttempting UI work after the fragment is detached.Check isAdded() before UI calls or move work to onViewCreated().
java.lang.OutOfMemoryErrorLoading large bitmaps without recycling.Use BitmapFactory.Options.inSampleSize or Glide/Picasso with proper caching.
android.content.ActivityNotFoundExceptionCalling startActivity() with an intent that no app can handle.Validate with resolveActivity() before launching.

7. Troubleshooting Common Issues

7.1 No Log Output Appears

  • Check USB debugging: Re‑enable the toggle and reconnect.
  • Device authorization: Run adb devices again; if it shows unauthorized, confirm the dialog on the phone.
  • ADB version mismatch: Ensure you use the latest platform‑tools; older versions may fail on newer Android releases.

7.2 Logcat Stops Mid‑Capture

  • Some OEMs impose a buffer limit. Use the -G option to increase the buffer size (requires root on older devices, but on many newer devices you can set it without root):
    adb logcat -G 16M
  • If the device disconnects, try a different USB port or cable.

7.3 “Permission denied” When Writing to File

  • On Windows, run the terminal as Administrator.
  • On macOS/Linux, ensure you have write permission to the directory (use sudo only if necessary).

8. Example Walkthrough: Fixing a NullPointerException in a Sample App

Suppose you downloaded a free weather app that crashes on launch. Follow the steps:

  1. Enable developer options and USB debugging (see Section 1).
  2. Install ADB (Section 2) and verify the device is listed (adb devices).
  3. Start a filtered logcat:
    adb logcat *:S AndroidRuntime:E > weather_crash.txt
  4. Open the weather app, watch it crash, then press Ctrl + C.
  5. Open weather_crash.txt and locate the stack trace. You find:
    java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.example.weather.WeatherInfo.city' on a null object reference
        at com.example.weather.ui.MainActivity.updateUI(MainActivity.java:78)
  6. Search the package name on GitHub; you discover the source is open‑source. Opening MainActivity.java at line 78 shows the app assumes the network response is non‑null.
  7. Solution: The developer adds a null‑check before accessing city. After the fix, the app launches correctly.

This example demonstrates how a concise logcat capture can save hours of guesswork.

9. Sharing Logs with Developers Safely

  • Remove any personally identifiable information (PII) before sending. Look for lines that contain your email, phone number, or location.
  • Compress the filtered file (zip filtered.txt) to keep the attachment size small.
  • When filing a bug report, include:
    • Device model and Android version (Settings → About phone).
    • App version (Settings → Apps → App → App details → Version).
    • The filtered logcat snippet.

10. Advanced Tips (Optional)

  • Use adb logcat -b crash to read the dedicated crash buffer that Android maintains for recent fatal crashes.
  • Persist logs across reboots by enabling “Developer options → Enable view attribute inspection” – this forces the system to keep a larger buffer.
  • Automate capture with a simple batch script:
    #!/bin/bash
    adb logcat -b crash -d > $(date +%Y%m%d_%H%M%S)_crash.txt
    Running the script after a crash gives you a timestamped file automatically.

With these steps you can reliably capture, filter, and interpret Android crash logs without rooting. Whether you’re a hobbyist developer, a power user troubleshooting a misbehaving app, or a support technician, the workflow outlined here gives you the data you need to diagnose the problem and communicate it effectively.

User Comments (0)

Add Comment
We'll never share your email with anyone else.