Back to skills
extension
Category: Development & EngineeringNo API key required

android-adb-debugging

Provides comprehensive Android Debug Bridge (ADB) commands and strategies for debugging, installing, monitoring, and interacting with Android applications during development. Use this skill when the user needs to debug an Android app, check logs, install APKs, capture screenshots, or simulate user interactions via command line.

personAuthor: awol2005exhubModelScope

Android ADB Debugging Skill

Overview

This skill provides a structured reference for using Android Debug Bridge (ADB) to interact with Android devices/emulators. It covers environment setup, application management, log analysis, file transfer, and UI automation.

Prerequisites

  • Android SDK Platform-Tools installed (adb in PATH).
  • USB Debugging enabled on the target device.
  • Device connected via USB or Wi-Fi.

Core Capabilities

1. Device Connection & Management

Use these commands to verify connectivity and manage device state.

| Action | Command | Notes | | :--- | :--- | :--- | | List Devices | adb devices | Check if device is authorized. | | Restart ADB Server | adb kill-server && adb start-server | Fix connection issues. | | Reboot Device | adb reboot | Normal reboot. | | Reboot to Bootloader | adb reboot bootloader | For flashing ROMs. | | Wireless Connect | adb tcpip 5555 <br> adb connect <IP>:5555 | Requires initial USB connection. |

2. Application Installation & Management

Commands to install, uninstall, and clear app data.

| Action | Command | Notes | | :--- | :--- | :--- | | Install APK | adb install path/to/app.apk | Fresh install. | | Reinstall (Keep Data) | adb install -r path/to/app.apk | Update existing app. | | Uninstall App | adb uninstall <package_name> | e.g., com.example.app | | Clear App Data | adb shell pm clear <package_name> | Resets app to fresh state. | | List Packages | adb shell pm list packages | Find package names. | | Grant Permission | adb shell pm grant <pkg> <perm> | e.g., android.permission.CAMERA |

3. Logcat & Debugging

Essential for diagnosing crashes and runtime behavior.

| Action | Command | Notes | | :--- | :--- | :--- | | View Logs | adb logcat | Real-time stream. | | Clear Logs | adb logcat -c | Clear buffer before testing. | | Filter by Tag | adb logcat -s MyTag | Case-sensitive tag filter. | | Filter by PID | adb logcat --pid=<pid> | Specific process. | | Save to File | adb logcat -d > logs.txt | Dump current buffer. | | Crash Stacktrace | adb logcat *:E | Show only errors. |

4. Screen Capture & Recording

Visual debugging tools.

| Action | Command | Notes | | :--- | :--- | :--- | | Screenshot | adb exec-out screencap -p > screen.png | Saves directly to host. | | Start Recording | adb shell screenrecord /sdcard/demo.mp4 | Max 180s. Press Ctrl+C to stop. | | Pull Recording | adb pull /sdcard/demo.mp4 . | Retrieve video file. |

5. File Transfer

Moving files between host and device.

| Action | Command | Notes | | :--- | :--- | :--- | | Push to Device | adb push local_file.txt /sdcard/ | Upload file. | | Pull from Device | adb pull /sdcard/file.txt . | Download file. | | List Files | adb shell ls /sdcard/ | Remote directory listing. |

6. UI Automation & Interaction

Simulating user input for testing.

| Action | Command | Notes | | :--- | :--- | :--- | | Tap Coordinate | adb shell input tap <x> <y> | Simulate touch. | | Swipe | adb shell input swipe <x1> <y1> <x2> <y2> <duration_ms> | Simulate swipe. | | Type Text | adb shell input text "Hello" | No spaces allowed directly (use %s). | | Key Event | adb shell input keyevent <code> | e.g., 4 (Back), 66 (Enter). | | Start Activity | adb shell am start -n <pkg>/<activity> | Launch specific screen. | | Force Stop | adb shell am force-stop <pkg> | Kill app process. |

Troubleshooting Common Issues

"Device Unauthorized"

  1. Check device screen for RSA fingerprint confirmation dialog.
  2. Run adb kill-server && adb start-server.
  3. Revoke USB debugging authorizations in Developer Options and reconnect.

"ADB Not Recognized"

  1. Ensure Android SDK Platform-Tools are installed.
  2. Add platform-tools directory to system PATH.
  3. Verify installation: adb version.

"More than one device connected"

Specify the target device using -s: adb -s <device_serial>

7. Performance Monitoring (性能监控)

Network & Traffic

| Action | Command | Notes | | :--- | :--- | :--- | | List Active Connections | adb shell ss -tunp | Shows IP:Port pairs. | | Filter Connections by UID | adb shell ss -tunp \| grep <uid> | Get UID via dumpsys package. | | Check Traffic Stats | adb shell dumpsys netstats \| grep <pkg> | Cumulative RX/TX data. | | Legacy Traffic Check | adb shell cat /proc/uid_stat/<uid>/tcp_rcv | Receive bytes only. |

CPU Usage

| Action | Command | Notes | | :--- | :--- | :--- | | Real-time Top | adb shell top -n 1 -o %CPU,PID,NAME | Snapshot of CPU usage. | | Continuous Monitor | adb shell top \| grep <package_name> | Live stream for specific app. | | Detailed CPU Info | adb shell dumpsys cpuinfo \| grep <pkg> | User/System split. |

Memory Usage

| Action | Command | Notes | | :--- | :--- | :--- | | Detailed Meminfo | adb shell dumpsys meminfo <pkg> | Look for "TOTAL PSS". | | Summary Meminfo | adb shell dumpsys meminfo --summary <pkg> | Quick overview. | | Java Heap Dump | adb shell am dumpheap <pid> /sdcard/heap.hprof | Then pull file for analysis. |

Disk I/O

| Action | Command | Notes | | :--- | :--- | :--- | | Process IO Stats | adb shell cat /proc/<pid>/io | May require Root access. | | Systrace for IO | python systrace.py -a <pkg> -t 5 io | Generates HTML trace file. |

Pro Tips for Performance Debugging

  1. PSS vs RSS: Always prefer PSS (Proportional Set Size) from dumpsys meminfo over RSS, as PSS accounts for shared memory libraries correctly.
  2. UID Mapping: To map network traffic to an app, first get the UID: adb shell dumpsys package com.example.app | grep userId. Then use that UID in ss or /proc/uid_stat/.
  3. IO Permissions: If /proc/<pid>/io is inaccessible, rely on systrace or Android Studio Profiler for detailed I/O breakdowns.