adb — Android Debug Bridge
command-line tool, lets you communicate with an emulator or connected Android device
2 min readApr 11, 2024
adb
is a client-server program that includes three components:
- client
— Sends a command to run on an Android device.
— The client runs on your development machine can be invoked with theadb
command. - daemon (adbd)
— Background process which runs commands sent by the client on an Android device. - server
— Background process that runs on the development machine; it manages communication between the client and the daemon.
→ adb
command-line utility included with Google’s Android SDK.
→ We can find adb tool
in Android SDK/platform-tools or Download ADB Kits.
→ adb
provides access to a Unix shell that you can use to run a variety of commands on a device such as below
- installing or uninstalling apps
- debugging apps
- push or pull files
- find connected devices
- kill & start adb server
Kill and start adb server
//Adb Server
adb kill-server
adb start-server
Reboot Device
//Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
adb root //restarts adb with root permissions
Connected Devices
adb usb
adb devices //show devices attached
adb devices -l //devices (product/model)
adb connect ip_address_of_device
Install or uninstall Apps
adb install -t path/to/app.apk
//with all runtime permissions granted
adb install -g <path/to/app.apk>
//Uninstalling app from device
adb uninstall com.myAppPackage
adb shell pm uninstall com.example.MyApp
adb shell pm clear [package] // Deletes all data associated with a package.
//prints package names for all applications installed on your phone
adb shell pm list packages
//Get device android version
adb shell getprop ro.build.version.release
Files
adb push [source] [destination] // Copy files from your computer to your phone.
adb pull [device file location] [local file location] // Copy files from your phone to your computer.
//App install
Logcat
adb logcat
adb logcat -c // clear // The parameter -c will clear the current logs on the device.
adb logcat -d > [path_to_file] // Save the logcat output to a file on the local system.
adb bugreport > [path_to_file] // Will dump the whole device information like dumpstate, dumpsys and logcat output.
Screenshot
#Create a temporary folder to save a screenshot.
mkdir tmp#Capture a screenshot and save to /sdcard/screen.png on your Android divice.
adb shell screencap -p /sdcard/screen.png
#Grab the screenshot from /sdcard/screen.png to /tmp/screen.png on your PC.
adb pull /sdcard/screen.png /tmp/screen.png
#Delete /sdcard/screen.png
adb shell rm /sdcard/screen.png
#open the screenshot on your PC.
open /tmp/screen.png
Screenrecord
adb shell screenrecord /mnt/sdcard/Download/test.mp4