1. ADB Basic Commands
adb devices
Lists all connected devices (physical or emulators).
Example:
adb devices
adb start-server
Starts the ADB server (if it is not already running).
Example:
adb start-server
adb kill-server
Stops the ADB server.
Example:
adb kill-server
adb version
Displays the current ADB version installed on your system.
Example:
adb version
adb help
Lists all available ADB commands and options.
Example:
adb help
2. Device Management
adb devices -l
Lists connected devices with additional information like model, serial number, and more.
Example:
adb devices -l
adb connect <device-ip>
Connect to a device over Wi-Fi using its IP address.
Example:
adb connect 192.168.1.100
adb disconnect
Disconnects the current device or emulator from ADB.
Example:
adb disconnect
adb -s <serial-number> <command>
Executes a command on a specific device (useful when multiple devices are connected).
Example:
adb -s emulator-5554 logcat
adb reboot
Reboots the connected Android device.
Example:
adb reboot
adb reboot bootloader
Reboots the device into the bootloader (useful for tasks like flashing custom ROMs).
Example:
adb reboot bootloader
adb root
Restarts the ADB daemon with root privileges (for rooted devices).
Example:
adb root
adb unroot
Restarts the ADB daemon with normal user privileges (for rooted devices).
Example:
adb unroot
3. App Management
adb install <path-to-apk>
Installs an APK on the connected device.
Example:
adb install path/to/your/app.apk
adb install -r <path-to-apk>
Reinstalls an APK, keeping the app data (useful for updating an app).
Example:
adb install -r path/to/your/app.apk
adb uninstall <package-name>
Uninstalls the app identified by the given package name.
Example:
adb uninstall com.example.myapp
adb shell pm list packages
Lists all installed packages on the device.
Example:
adb shell pm list packages
adb shell pm clear <package-name>
Clears the app data for the given package name.
Example:
adb shell pm clear com.example.myapp
4. Logcat (Log Management)
adb logcat
Displays the log output from the device (default is system and app logs).
Example:
adb logcat
adb logcat -d
Dumps the current log and exits (useful for saving logs).
Example:
adb logcat -d > log.txt
adb logcat -s <tag>
Filters log output by a specific tag (useful for narrowing down specific logs).
Example:
adb logcat -s MyAppTag
adb logcat *:E
Filters to show only error messages.
Example:
adb logcat *:E
5. File Transfer & Management
adb push <local-path> <remote-path>
Pushes a file or directory from your local machine to the device.
Example:
adb push myfile.txt /sdcard/
adb pull <remote-path> <local-path>
Pulls a file or directory from the device to your local machine.
Example:
adb pull /sdcard/myfile.txt .
adb shell
Starts a shell on the connected device for running system commands.
Example:
adb shell
adb shell ls <directory-path>
Lists files in a specific directory on the device.
Example:
adb shell ls /sdcard/
6. Emulator Commands
adb emu <command>
Sends commands to an emulator instance (for advanced use).
Example:
adb emu kill
adb -s emulator-5554 emu kill
Terminates the running emulator instance.
Example:
adb -s emulator-5554 emu kill
adb -s emulator-5554 emu avd
Starts the AVD (Android Virtual Device) emulator.
Example:
adb -s emulator-5554 emu avd
7. Backup and Restore
adb backup -apk -shared -all -f <backup-file>
Backs up the device data, including APKs and shared data.
Example:
adb backup -apk -shared -all -f mybackup.ab
adb restore <backup-file>
Restores data from a previously created backup.
Example:
adb restore mybackup.ab
8. Advanced Commands
adb shell am start <activity>
Starts an Android activity (this can be useful for launching your app or specific parts of it).
Example:
adb shell am start -n com.example/.MainActivity
adb shell pm enable <package-name>
Enables a previously disabled app or package.
Example:
adb shell pm enable com.example.myapp
adb shell pm disable <package-name>
Disables a package or app on the device.
Example:
adb shell pm disable com.example.myapp
adb shell screencap -p <filename>
Takes a screenshot of the device and saves it as a PNG file.
Example:
adb shell screencap -p /sdcard/screenshot.png
adb shell screenrecord <filename>
Records the device’s screen into a video file.
Example:
adb shell screenrecord /sdcard/demo.mp4
adb tcpip 5555
Restarts the ADB daemon in TCP/IP mode to allow wireless communication over a specific port.
Example:
adb tcpip 5555
Summary
These ADB commands cover a wide range of functionality for installing apps, debugging, transferring files, and device management. As a .NET MAUI developer, you’ll likely use a subset of these commands most often, but knowing them can help you troubleshoot, manage devices, and test Android-specific functionality more effectively.
Leave a Reply