Mobile Development 16 min read

Mastering ADB: Essential Commands for Android Device Management

This guide explains the architecture of ADB, how to install it, and provides a comprehensive list of commands for connecting devices, managing apps, transferring files, capturing screenshots, controlling the shell, and performing performance analysis on Android devices.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Mastering ADB: Essential Commands for Android Device Management

Introduction

ADB (Android Debug Bridge) is a versatile command‑line tool that enables developers to perform device operations such as installing and debugging apps, accessing a Unix shell on the device, and retrieving system information. It follows a client‑server architecture consisting of a client (run on the development PC), a daemon (running on each device), and a server (running on the PC and mediating communication via TCP port 5037).

How ADB Works

When an ADB client starts, it checks for a running server; if none exists, it launches one that binds to port 5037. The server then discovers connected devices (including emulators on ports 5555‑5585) and establishes communication with each device’s daemon.

Downloading ADB

Download links for the ADB binaries and a graphical tool (APKInstaller) are provided. After extracting, add the ADB directory to the system PATH to use the commands from any location.

Basic Operations

Device Connection

adb connect 127.0.0.1:62001  # connect to an emulator

Start/Stop Server

adb start-server   # start the ADB server
adb kill-server    # stop the ADB server

Device Management

adb devices                # list connected devices</code><code>adb version                # show ADB version</code><code>adb get-state              # show device state (device/offline/unknown)</code><code>adb get-serialno          # get device serial number</code><code>adb shell cat /system/build.prop   # display device build properties

Multiple Devices

adb -a                     # listen on all network interfaces</code><code>adb -d                     # target USB device (if multiple are connected)</code><code>adb -e                     # target TCP/IP device</code><code>adb -s <serial>           # specify device by serial number

Service Control

adb tcpip 5555            # set device to listen on TCP port 5555</code><code>adb disconnect 127.0.0.1:62001   # disconnect a device

Root Access

adb root                 # restart adbd with root privileges</code><code>adb unroot               # drop root privileges

Reboot Options

adb reboot               # normal reboot</code><code>adb reboot bootloader    # reboot to bootloader (fastboot) mode</code><code>adb reboot recovery     # reboot to recovery mode

App Management

adb shell pm list packages                # list all packages</code><code>adb shell pm list packages -s             # list system apps</code><code>adb shell pm list packages -3             # list third‑party apps</code><code>adb shell pm clear <package>               # clear app data and cache

Install / Uninstall

adb install D:/aa.apk                       # install APK from PC</code><code>adb install -r D:/aa.apk                    # reinstall, keep data</code><code>adb uninstall -k <package>                 # uninstall but keep data

Logcat

adb logcat                                 # view device logs</code><code>adb logcat -v time > D:\log.txt          # save logs to a file</code><code>adb logcat -c                             # clear log buffer

File Transfer

adb push C:\path\file.png /sdcard/        # push file to device</code><code>adb pull /sdcard/file.png C:\path\        # pull file from device

Screen Capture & Recording

adb shell screencap /sdcard/1.png          # capture screenshot on device</code><pre><code>adb exec-out screencap -p > 1.png          # capture screenshot to PC
adb shell screenrecord /sdcard/1.mp4      # record screen (Android 4.4+)

Shell Interaction

adb shell                                   # enter device shell</code><code>exit                                       # leave shell

Device Information

adb shell getprop ro.build.version.release   # Android version</code><code>adb shell getprop ro.product.model          # device model</code><code>adb shell wm size                          # screen resolution</code><code>adb shell wm density                       # screen density

Process Management

adb shell ps                               # list running processes</code><code>adb shell kill <pid>                       # kill a process

Performance Monitoring

adb shell top                              # real‑time CPU/memory usage</code><code>adb shell dumpsys meminfo <package>        # memory usage of a package

Input Simulation

adb shell input keyevent 3                 # HOME button</code><code>adb shell input tap 100 300                # tap at coordinates</code><code>adb shell input swipe 100 1200 100 200   # swipe up</code><code>adb shell input text hello                # input text

Network Control (requires root)

adb shell svc wifi enable                  # enable Wi‑Fi</code><code>adb shell svc wifi disable                 # disable Wi‑Fi

Port Forwarding

adb forward tcp:60 tcp:70                  # forward local port 60 to remote 70

Activity Management

adb shell am start -n com.example/.MainActivity   # launch an activity</code><code>adb shell am start -a android.intent.action.VIEW -d https://www.baidu.com   # open URL in browser

Conclusion

The article covers the full range of ADB capabilities, enabling developers to control Android devices, manage applications, capture media, analyze performance, and automate testing without relying on the full Android SDK.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Mobile DevelopmentAndroidAutomationADBdevice management
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.