anr-deadlock-detective

Diagnose Android ANRs and main-thread deadlocks from traces, logs, and Perfetto captures.

Updated Jan 2, 2024
One-click install
npx skills add https://github.com/Mithrandir21/game-deals-app --skill anr-deadlock-detective-mithrandir21
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: anr-deadlock-detective
Source: https://github.com/Mithrandir21/game-deals-app/tree/main/.claude/skills/anr-deadlock-detective
Command: npx skills add https://github.com/Mithrandir21/game-deals-app --skill anr-deadlock-detective-mithrandir21

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Android apps freeze with "Application Not Responding" dialogs when the main thread is blocked, and the fix is rarely obvious from a stack trace alone. This Skill provides a structured process for reading ANR traces, identifying what blocked the main thread, and applying the correct fix. ## Core Features & Use Cases - Trace Analysis: Pattern-matches the top frames of the main thread stack in traces.txt or adb bugreport output to identify waits, binder calls, disk I/O, and runBlocking deadlocks. - Root Cause Categorization: Classifies the blocker into main-thread I/O, coroutine deadlock, slow binder calls, lock contention, or frame-time overflow, each with a matching fix strategy. - Fix Verification: Guides reproduction on low-end devices, StrictMode checks, and Macrobenchmark assertions to confirm the ANR is resolved. - Use Case: A Crashlytics report shows an ANR with the main thread parked in LockSupport.park. Use this Skill to trace which thread holds the lock, identify a runBlocking coroutine deadlock, and refactor the caller to be suspend-aware. ## Quick Start Analyze this ANR trace from traces.txt and tell me what is blocking the main thread and how to fix it.

Frequently Asked Questions about anr-deadlock-detective

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix an Android ANR input dispatching timed out error?▼

An input dispatching timeout means the main thread was blocked for about 5 seconds. Pull the ANR trace from /data/anr/traces.txt or adb bugreport, find the main thread's top frames, and match them to a cause such as disk I/O, a binder call, or a lock wait, then move that work off the main thread.

How to read an Android ANR stack trace from traces.txt?▼

Locate the "main" thread in the trace and examine its top frames. Frames like Object.wait or LockSupport.park indicate waiting on a lock, Binder.transact indicates blocking IPC, and nativePollOnce means the main thread was idle so the cause lies elsewhere, such as the input dispatcher or another thread.

What causes runBlocking deadlocks in Kotlin coroutines on Android?▼

A runBlocking call on the main thread that awaits a coroutine scheduled on Dispatchers.Main deadlocks because the main thread is blocked and can never resume the awaited coroutine. Fix it by making the caller suspend-aware or moving the awaited work to Dispatchers.Default or Dispatchers.IO.

Why does nativePollOnce appear at the top of my ANR trace?▼

nativePollOnce means the main thread is idle in its message loop, not that it caused the ANR. The real cause is elsewhere: check recent binder calls, the input dispatcher state, other threads' activity, or system-level pressure on the device.

Can SharedPreferences cause an ANR on Android?▼

Yes. Calling SharedPreferences commit() on the main thread performs synchronous disk writes that can block long enough to trigger an ANR. Switch to apply(), which writes asynchronously, or migrate to DataStore for coroutine-based persistence.

When should I use a recomposition profiler instead of ANR analysis?▼

Use recomposition or startup profiling when the screen merely feels slow or janky without an actual hang or ANR dialog. ANR analysis applies when the main thread is truly blocked, producing input dispatching timeouts, traces.txt entries, or Crashlytics ANR reports.