Essential ADB Commands for Android Development and Testing

Essential ADB Commands for Android Development and Testing

Table of Contents

If you work with Android devices, you’ve likely encountered ADB (Android Debug Bridge). If not, now is the perfect time to learn about this powerful tool that’s essential for Android development and testing.

What is ADB?

ADB (Android Debug Bridge) is a versatile command-line tool that lets you communicate with Android devices. It’s an essential tool for developers and QA engineers, enabling tasks like installing apps, debugging, and accessing device features directly from your computer.

Most Common ADB Commands

Here’s a collection of the most frequently used ADB commands from my QA experience:

Device Connection

# Connect to a device over network
adb connect [device_ip]

# List all connected devices
adb devices

# Restart ADB server
adb kill-server
adb start-server

# Reboot device
adb reboot

App Installation

# Install an APK
adb install [path_to_apk]

Pro tip: You can simply drag and drop the APK file into your terminal after typing adb install to automatically fill in the path!

Screen Capture

# Take a screenshot
adb shell screencap -p /sdcard/screen.png

# Record screen
adb shell screenrecord /sdcard/video.mp4
# Press Ctrl+C to stop recording

File Management

# Copy files from device to computer
adb pull /sdcard/screen.png /Users/your_username/Desktop/

# Delete files on device
adb shell rm /sdcard/video.mp4

Debugging

# Get device logs
adb logcat -v time > log.txt

# Input text via shell
adb shell input text "your_text_here"

Installing ADB on macOS

The easiest way to install ADB on macOS is using Homebrew:

# Install Homebrew if you haven't already
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install ADB
brew install android-platform-tools

After installation, verify it’s working by running:

adb version

Installing ADB on Linux

On Linux, you can install ADB using your distribution’s package manager:

Ubuntu/Debian

# Update package list
sudo apt-get update

# Install Android tools package
sudo apt-get install android-tools-adb android-tools-fastboot

Fedora

sudo dnf install android-tools

Arch Linux

sudo pacman -S android-tools

After installation, verify it’s working by running:

adb version

Tips for Using ADB Effectively

  1. Enable USB Debugging: On your Android device, go to Settings > Developer options and enable USB debugging. If you don’t see Developer options, go to Settings > About phone and tap Build number seven times.

  2. Network Debugging: For wireless debugging, ensure your device and computer are on the same network. First, connect via USB and run:

    adb tcpip 5555
    

    Then you can connect wirelessly using adb connect [device_ip]:5555

  3. Multiple Devices: If you have multiple devices connected, specify the target device using its serial number:

    adb -s [device_serial] [command]
    

Common Issues and Solutions

Device Not Found

If your device isn’t being recognized:

  1. Check USB debugging is enabled
  2. Try a different USB cable
  3. Restart ADB server:
    adb kill-server
    adb start-server
    

Installation Failed

If app installation fails:

  1. Check if the app is already installed
  2. Ensure you have enough storage space
  3. Try uninstalling the existing version first:
    adb uninstall com.package.name
    

Conclusion

ADB is an invaluable tool for Android development and testing. These commands represent just a fraction of what’s possible with ADB, but they cover the most common use cases you’ll encounter in day-to-day development and QA work.

Remember to keep your ADB tools updated and always ensure you’re following security best practices when using ADB, especially when connecting to devices over a network.

Related Posts

Alexander Wahl

Alexander Wahl

I am a Senior QA Automation Engineer with focus on Python and API Testing & Python Developer.

Read More

Alexander Wahl

Download CV (PDF)

Professional Summary

Software professional with proven experience in QA Automation and Python Development. Specialized in building test automation frameworks and backend systems, with expertise in Python, Django, FastAPI, and API testing.

Read More
Complete Guide: Setting Up a Secure Home Server Infrastructure

Complete Guide: Setting Up a Secure Home Server Infrastructure

This article is the result of my research dedicated to solving the problem of using a dynamic IP address when hosting a website or application on a home server.

Read More