Ever wanted to use ADB but were scared by all the commands that you had no idea how to even start? Worry not! Here, we will try and explain some of the basic commands required for everyday usage.
Before we begin, please note that everything written here is tested on both Windows 7 and 10, workstation variants. Unless specified otherwise, all the commands will be written assuming that you are running Windows.
What is ADB?
Android Debug Bridge (ADB) is a versatile command-line tool that lets you communicate with an emulator instance or connected Android-powered device. The ADB toolkit provides several useful commands, and as such it’s a crucial part of Android SDK Platform Tools.
What does ADB do?
As the name suggests, ADB acts as a bridge between your development machine and an Android device or emulator.
You can issue commands to your device or emulator using the ADB tool, which in turn allows you to debug and test your applications on physical hardware or in an emulator environment.
There Are a Few Key Things That You Can do With ADB:
1) Debug an Android application
2) Push an Android application to your device
3) Pull an Android application from your device
4) Manage files on the emulator or the actual target device
5) Run shell commands on either of them
ADB is especially useful when it comes to debugging your applications via breakpoints. As you probably know, breakpoints allow you to pause a running program in order to examine the contents of variables and so on.
ADB can be used to set breakpoints from your development machine, which makes it easy for developers to debug their applications.
What is SDK Platform Tools?
SDK platform tools refer specifically to several command-line utilities that are part of the Android SDK platform-tools package. Those tools are:
* adb – Android Debug Bridge, which lets you manage the state of an emulator instance or Android-powered device
* ddms – Dalvik Debug Monitor Server, for debugging
* layoutlib – A library for inspecting the layout
* monkeyrunner – A library used for writing instrumentation tests in Python
* ProGuard – A tool that minimizes, optimizes and obfuscates your code
* smali – An assembler/disassembler for Android’s classfile format
They are included with the default installation of the Android SDK. They may be updated via the Android SDK Manager.
The first step is to install Android SDK on your machine. If you have already done so, skip this step and move to the next one. If not, please follow the instructions given at https://developer.android.com/studio/install/sdk-manager.html
Once you have installed Android SDK, open the SDK Manager and install at least these packages: “Android SDK Platform-tools”, “Android SDK Build-tools” and the lates Android version.
Now That we Have Set up the Development Environment, Let us Move on to the Commands.
This command shows all the connected devices. If your device is not listed here, please check if you have enabled USB debugging on your device. If not, please follow the instructions given at https://developer.android.com/studio/debug/index.html
adb reboot recovery
This command reboots your device into recovery mode.
adb reboot bootloader
This command reboots your device into bootloader mode.
adb reboot download
This command simulates a USB connection between adb and your Android device. You can use this command to avoid having to physically connect/disconnect the cable every time you want to reboot your phone.
adb install path_to_apk_file
This command installs an Android application on your device. It takes one parameter, which is the apk file name of the app that you would like to install.
Please note that it will not replace any existing apps that might already be installed on your device with the same name as the app you are trying to install. For example, if “ExampleApp” is already installed on your device and you try to install “ExampleApp2” using this command, it will not do anything.
adb uninstall path_to_apk_file
This command uninstalls an Android application on your device. It takes one parameter, which is the apk file name of the app that you would like to uninstall.
This command changes the adb daemon from a regular user to a root user so that all commands will be executed with elevated privileges. Note: Make sure you have enabled USB debugging before running this or any other adb commands as a root user!
Also remember that by doing this, you are opening up your device to all sorts of security issues including but not limited to complete data wipe in case something goes wrong. Use this command with caution!
adb push path_to_file_on_PC path_to_file_on_device
This command copies a file from your computer to your Android device. It takes two parameters, first one is the local path on your computer of the file that you want to copy and second one is the remote path on your Android device where you want to copy the file.
adb pull path_to_file_on_device path_to_file_on_PC
This command copies a file from your Android device to your computer. It takes two parameters, first one is the remote path on your Android device of the file you want to copy and second one is the local path on your computer where you want to copy the file.
This command opens up a shell on your Android device from where you can execute all sorts of commands. Please note that not all of these commands will work on every Android device as different devices have different implementations. Also, some of the commands might require root privileges to be executed.
This command prints out the logcat buffer to the console. Logcat is a very powerful tool and can be used to debug all sorts of issues on your Android device. You can learn more about it at https://developer.android.com/studio/debug/logcat.html
This command gives you a list of all the adb commands along with their descriptions.
This is an overview of some basic ADB commands that you might find useful when starting out with Android Development. For a more comprehensive list of commands and their descriptions, please refer to the official Android documentation.
Note that not all of these commands will work on every Android device as different devices have different implementations. Also, some of the commands might require root privileges to be executed.