July 9, 2025
10 min read

Mastering ADB: Enhancing Android/AOSP Development with Powerful Commands

ADB
Android
AOSP
Development
Debugging
SSamir Dubey
Samir Dubey

AOSP Engineer

Explore the power of Android Debug Bridge (ADB) with essential commands for Android and AOSP development, covering debugging, file transfers, system modifications, and more.

ADB (Android Debug Bridge) is a valuable command-line tool used by developers and advanced users to interact with Android devices connected to a computer. It serves as a bridge, establishing a connection between the Android device and the host system, allowing users to execute various commands on the device through a USB connection or over a network.

Developers find ADB indispensable during the Android app development process. It enables them to install and uninstall applications, transfer files, run shell commands, debug apps, take screenshots, and record device screen activity for testing purposes. By facilitating the deployment of applications from a computer to a device for testing and debugging, ADB streamlines the development workflow.

Moreover, ADB provides access to the device's log files, assisting in issue diagnosis and system event monitoring. Additionally, it allows developers to simulate different hardware configurations, enabling them to assess app behavior across a variety of devices.

Basic ADB Commands

adb devices: This command lists all the Android devices connected to the computer, along with their unique device IDs (UDID). It helps verify if the device is properly connected and ready for interaction.

adb kill-server: Command shuts down the ADB server running on your computer. It stops all ADB services and disconnects any connected devices. It is typically used when you encounter connection issues or when you need to restart the ADB server for any reason.

adb start-server: Command starts the ADB server on your computer. It initiates the ADB services, allowing you to use ADB commands to interact with Android devices connected to your computer.

adb reboot: After executing this command, the device will power off and then power on again, just like when you manually restart it using the device's physical power button.

adb shell df: Shows the amount of disk space used and available on the device's file systems.

File Transfer

adb push <local_path> <remote_path>: This command transfers files from the local (computer) to the remote (Android device) using the Android Debug Bridge (ADB). It allows developers to push files, such as apps, data, or configuration files, from their computer to the device.

Example: adb push myfile.txt /sdcard/

adb pull <remote_path> <local_path>: This command transfers files from the remote (Android device) to the local (computer). It is useful for retrieving files, logs, or any data generated on the Android device during testing or debugging.

Example: adb pull /sdcard/screenshot.png C:UsersMyUserDocuments

Both commands are essential for seamless file transfer between the computer and Android device during app development, testing, and debugging processes. They help developers manage data flow and ensure the proper functioning of their applications on different devices.

ADB getprop

adb shell getprop: Retrieves the value of a specified system property from the connected Android device. System properties hold essential information about the device's configuration.

Example: adb shell getprop ro.product.model

adb shell cat /proc/cpuinfo: Displays detailed information about the device's CPU (Central Processing Unit), including its architecture, features, and clock speed.

adb shell getprop ro.build.version.release: Retrieves the Android OS version running on the device.

adb shell getprop ro.build.version.sdk: Retrieves the Android SDK version used for building the system image.

APK Install

adb install <APK_NAME>: Installs the specified APK on the Android device.

Example: adb install example_app.apk

-r : Reinstalls the APK, keeping its data and overwriting the existing installation.

-l : Installs the APK without starting it (stands for "lock").

-t : Allows installation of APKs that target a different Android version than the connected device.

-s : Installs the APK on the SD card if the device supports it.

-d : Allows the APK installation over a version with a lower version code.

-g : Grants all runtime permissions during installation.

These ADB install commands provide various options for deploying Android apps (APKs) on connected devices, allowing developers to test and manage installations efficiently during the development and debugging process.

Uninstall Apps

adb uninstall <package_name>: Uninstalls the specified Android app (package) from the connected device.

Example: adb uninstall com.example.app

adb uninstall -k <package_name>: Uninstalls the app and keeps its data and cache directories on the device (keeps data).

Example: adb uninstall -k com.example.app

These ADB commands allow developers to uninstall Android applications directly from the connected device. The second command (adb uninstall -k) provides an option to retain the app's data and cache directories, useful for debugging or temporary uninstallations without losing user data.

Package Manager

adb shell pm list package: Lists all installed packages on the Android device.

adb shell pm list package -s: Lists only system packages (pre-installed apps) on the Android device.

adb shell pm list package -3: Lists third-party packages (user-installed apps) on the Android device.

adb shell pm list package -f: Lists all installed packages along with their associated APK file paths.

adb shell pm list package -¡: Lists all packages with their installer (installer package) on the Android device.

adb shell pm path com.example.com: Shows the APK file path for the package "com.example.com".

adb shell pm dump com.example.com: Dumps detailed information about the package "com.example.com", including permissions, activities, and services.

These Package Manager commands provide insights into the installed packages, their types, APK file paths, and detailed information about specific packages on the Android device. They are valuable for developers and advanced users to manage and inspect installed applications and their associated data.

Logcat

adb logcat: This command displays logs from the connected Android device on the computer's terminal. By default, it shows all log levels (Verbose to Error).

adb shell "logcat >/sdcard/log000.log": This command saves all logs from the Android device to a file named "log000.log" in the device's /sdcard directory.

adb logcat | grep -E "^..<tag1>|^..<tag2>": This command filters the logcat output and shows only the log entries whose tags start with "tag1" or "tag2."

Example: adb logcat | grep -E "^..MyApp|^..MyActivity"

adb logcat | grep -vE "^..<tag1>|^..<tag2>": This command excludes log entries whose tags start with "tag1" or "tag2" from the logcat output.

Example: adb logcat | grep -vE "^..MyApp|^..MyActivity"

adb logcat -c && adb logcat –: This command clears the logcat cache and then starts displaying the current log entries continuously. It ensures you view only the current logs.

The next set of commands demonstrates different logcat filtering options based on the log level and tag:

adb logcat <tag>[:priority]: Filters logs by specific tag and, optionally, priority level (V, D, I, W, E, F, or S).

*adb logcat :E: Displays logs with a priority level of Error (E) for all tags.

adb logcat -v time: Adds timestamps to log entries for better time tracking.

*adb logcat -v time :E: Displays Error (E) logs with timestamps.

adb logcat -v time >D:log.txt: Saves logcat output to a file named "log.txt" with timestamps.

These adb logcat commands aid developers in effectively monitoring and analyzing logs generated by Android applications and system processes, which is crucial for debugging and optimizing app performance.

Window Manager

adb shell wm help: This command displays a list of available Window Manager (WM) commands and their descriptions, providing developers with a reference for using WM functionalities.

adb shell wm size: Retrieves the current display size of the device in pixels. It helps developers adapt their applications to different screen sizes and resolutions.

adb shell wm density: Shows the current display density of the device, which determines how many pixels are considered within a certain physical area. This is crucial for handling different screen densities in Android app development.

adb shell wm size <width>x<height>: Sets a custom display size for the device. This can be useful for testing app behavior on specific screen resolutions.

Example: adb shell wm size 720x1280

adb shell wm density <density>: Sets a custom display density for the device. This allows developers to simulate different screen densities during app testing.

Example: adb shell wm density 240

adb shell wm size reset: Resets the display size to its default value, undoing any previous customizations.

These Window Manager commands help developers manage the device's display size and density, ensuring their applications are optimized for various screen configurations and offering a better user experience across a wide range of Android devices.

Filtering processes through ADB

adb shell ps | grep <pattern>: This command lists all running processes on the Android device and then filters the output using the "grep" command to display only the lines containing the specified pattern.

Example: adb shell ps | grep myapp

adb shell ps -t -x, -P, -p, -c [pid|name]: This command is a general representation of several options that can be used with the adb shell ps command to list processes based on specific criteria. The available options are:

-t: Display the process's thread information.

-x: Include processes with no controlling terminal.

-P: Show the scheduling group associated with each process.

-p: Show only processes with specific PIDs (Process IDs) or a single PID.

-c: Output in a compact form, displaying only the process names.

Example: adb shell ps -t

These commands are useful for viewing information about running processes on the Android device, which can be beneficial for debugging and understanding the system's current state. The grep command, when used with adb shell ps, helps to filter and focus on specific processes or their attributes.

Device System Modifications

adb root: This command restarts the adb daemon with root privileges. It grants adb elevated permissions on the Android device, allowing access to system files and directories typically restricted to regular users.

Note: Some devices may not support this command, as it depends on the device's configuration.

adb disable-verity: This command disables dm-verity, a security feature that verifies the integrity of system partitions. Disabling dm-verity allows modifications to the system partition, such as installing custom ROMs or making changes to system files.

Note: This command may only work on devices with an unlocked bootloader.

adb remount: This command remounts the /system partition of the Android device in read-write mode. The /system partition is usually mounted as read-only to protect critical system files. Remounting it as read-write allows changes to be made to the system partition.

Screen Capture and Recording

adb shell screencap -p /sdcard/screen.jpg: Capture a screenshot of the Android device's screen and save it as "screen.jpg" in the /sdcard directory.

adb shell screenrecord sdcard/record.mp4: Record the screen activity of the Android device and save it as "record.mp4" in the /sdcard directory.

Activity Operations

adb shell dumpsys activity: Dumps detailed information about the activity manager and all running activities on the Android device. This command provides a comprehensive overview of the current state of activities, recent tasks, and other activity-related data.

adb shell "dumpsys activity | grep 'Activity:'": Pipes the output of dumpsys activity through the grep command to filter and display only lines containing "Activity:" in the output. This helps to show information specifically related to activities running on the device.

These ADB shell commands are valuable for developers and power users to inspect the activity manager and understand the current state of activities on the Android device. They aid in debugging and optimizing the behavior and performance of Android applications.

adb shell setprop persyst.system.value true:: Sets the value of the system property "persyst.system.value" to "true" on the Android device. System properties are key-value pairs that configure various system behaviors and settings.

adb shell dumpsys package queries: Dumps information about the queries performed by packages on the Android device. This command provides details about the package queries executed by applications.

adb shell dumpsys procstats: This command provides detailed information about the current state of processes and services running on the Android device. It includes memory usage, process counts, and other statistics related to the device's performance.

Example: adb shell dumpsys procstats

adb shell dumpsys gfxinfo: This command retrieves graphics rendering information, such as frame times and jank metrics, for the specified application or system-wide. It helps developers analyze the graphics performance of an app and identify potential issues related to smoothness and responsiveness.

These ADB commands offer control over system properties and allow developers to inspect package queries executed by applications on the Android device. Proper use of these commands can help fine-tune system settings and understand app behavior during development and testing.

adb shell am start package_name/.Activity: This command starts an activity within an Android app using the am (Activity Manager) tool via ADB (Android Debug Bridge). It launches the specified activity (denoted by "Activity") from the package specified by "package_name". This command is commonly used for testing and debugging purposes.

Example: adb shell am start com.example.myapp/.MainActivity

adb shell am start -W -n package_name/.Activity: Similar to the previous command, this starts an activity within an Android app. The -W option waits for the launch to complete and reports the launch time. The -n option is used to specify the component name, consisting of the package name followed by the activity name.

Example: adb shell am start -W -n com.example.myapp/.DetailActivity

adb shell am start -a android.intent.action.MAIN -n — ei pid 10 — es str "helloworld":

This command starts an activity with specific action and extras. The -a option specifies the action to be performed, and -n specifies the component name. The — ei option sets an integer extra named "pid" with a value of 10, and the — es option sets a string extra named "str" with the value "helloworld".

Example: adb shell am start -a android.intent.action.VIEW -n com.example.myapp/.MainActivity — ei count 5 — es message "Hello, World!"

adb shell am force-stop package_name: This command forcefully stops the specified Android app package. It terminates all the processes associated with the package, allowing you to reset the app to its initial state or perform certain debugging tasks.

Example: adb shell am force-stop com.example.myapp

adb shell pm clear package_name: This command clears all data associated with the specified Android app package. It removes all the app's data, cache, and preferences, effectively resetting the app to its initial state as if it were freshly installed.

Example: adb shell pm clear com.example.myapp

Service Operations

adb shell am startservice -n /.

  • Initiates the specified service from the given package on the Android device.

Example: adb shell am startservice -n com.example.app/com.example.app.MyService

adb shell am start-foreground-service -n com.demo.screenrecorder/com.demo.screenrecorder.RecordService

  • Launches the "RecordService" as a foreground service from the "com.demo.screenrecorder" package on the Android device.

Example: adb shell am start-foreground-service -n com.demo.screenrecorder/com.demo.screenrecorder.RecordService

These ADB commands allow you to start services from specific packages on the Android device. Starting services is essential for various background tasks and functionality within Android applications.

Broadcast through adb

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

  • Broadcasts the BOOT_COMPLETED intent, typically used to inform apps that the device has completed the boot process.

Example: adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED

  • Broadcasts the MEDIA_MOUNTED intent, indicating that an external media (e.g., SD card) has been mounted and is ready for access.

Example: adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED

adb shell am broadcast -a android.intent.action.MEDIA_UNMOUNTED

  • Broadcasts the MEDIA_UNMOUNTED intent, indicating that an external media (e.g., SD card) has been unmounted and is no longer accessible.

Example: adb shell am broadcast -a android.intent.action.MEDIA_UNMOUNTED

adb shell am broadcast -a car.meter.share.BROADCAST

  • Sends a custom broadcast with the action car.meter.share.BROADCAST.

Example: adb shell am broadcast -a car.meter.share.BROADCAST

adb shell am broadcast -a com.leapmotor.share.reload.BROADCAST

  • Sends a custom broadcast with the action com.leapmotor.share.reload.BROADCAST.

Example: adb shell am broadcast -a com.leapmotor.share.reload.BROADCAST

adb shell am broadcast -a com.android.test — es test_string "this is test string" — ei test_int 100 — ez test_boolean true

  • Sends a custom broadcast with the action com.android.test and includes extras such as a test string, integer, and boolean values.

Example: adb shell am broadcast -a com.android.test — es test_string "Hello, World!" — ei test_int 42 — ez test_boolean true

These ADB commands enable you to broadcast different intents and custom events to Android apps. Broadcasting intents is a way to trigger specific actions or inform apps about certain events or changes in the system or device environment.

View Network Information with ADB

adb shell ping -c 4 www.google.com

Description: Pings the "www.google.com" website four times from the Android device to check connectivity and measure round-trip time (RTT).

Example: adb shell ping -c 4 www.google.com

adb shell netstat

  • Displays active network connections on the Android device, including established connections, listening ports, and routing information.

Example: adb shell netstat

tcpdump -p -vv -s 0 -w /data/data/capture.pcap

  • Captures network traffic on a specific interface and saves it to "/data/data/capture.pcap" on the Android device. Requires root access.

Example: tcpdump -p -vv -s 0 -w /data/data/capture.pcap

tcpdump -p any -s 0 -w /data/data/capture.pcap

  • Captures network traffic on any available interface and saves it to "/data/data/capture.pcap" on the Android device. Requires root access.

Example: tcpdump -p any -s 0 -w /data/data/capture.pcap

These ADB commands provide network-related information on the Android device. You can check network connectivity with ping, view active connections with netstat, and capture network traffic using tcpdump for analysis and debugging purposes. Note that some commands may require root access to function properly.

adb shell getevent

  • Retrieves and displays real-time input events generated by the touchscreen, keyboard, and other input devices on the Android device. This command allows you to monitor input events, such as touch gestures, key presses, and other interactions.

Example: adb shell getevent

Simulate Click and Input Events with ADB

adb shell input mouse tap x y

  • Simulates a tap/click event at the specified coordinates (x, y) on the Android device's screen using the mouse input.

Example: adb shell input mouse tap 200 300

adb shell input swipe x1 y1 x2 y2

  • Simulates a swipe gesture starting from coordinates (x1, y1) to coordinates (x2, y2) on the Android device's screen.

Example: adb shell input swipe 300 500 300 300

adb shell input text 'string'

  • Simulates text input by typing the specified 'string' on the Android device's active text input field.

Example: adb shell input text 'Hello, World!'

adb shell input keyevent 4

  • Simulates a key press event for the "Back" button on the Android device.

Example: adb shell input keyevent 4

These ADB commands allow you to simulate user interactions on the Android device. You can use them for testing, automation, and debugging purposes to emulate various touch events, swipes, text input, and key presses without physically interacting with the device.

Accessing Android Settings with ADB

adb shell settings

  • Accesses and displays all available Android settings and their configurations.

Example: adb shell settings

adb shell settings list system

  • Lists all system settings available on the Android device.

Example: adb shell settings list system

adb shell settings get system <setting_name>

  • Retrieves the current value of a specific system setting on the Android device.

Example: adb shell settings get system volume_system

adb shell settings get system notification_sound

  • Retrieves the current notification sound setting on the Android device.

Example: adb shell settings get system notification_sound

adb shell settings list secure

  • Lists all secure settings available on the Android device.

Example: adb shell settings list secure

adb shell settings get secure android_id

  • Retrieves the value of a specific secure setting, such as the Android ID, on the Android device.

Example: adb shell settings get secure android_id

adb shell settings list global

  • Lists all global settings available on the Android device.

Example: adb shell settings list global

adb shell settings get global <setting_name>

  • Retrieves the value of a specific global setting, such as mobile data and Wi-Fi status, on the Android device.

Examples:

adb shell settings get global mobile_data

adb shell settings get global wifi_on

These ADB commands provide access to various Android settings, allowing you to retrieve and manage configurations related to system, secure, and global settings. This functionality is helpful for developers and system administrators to check and modify specific settings programmatically during testing or development.