What is adb?
Android Debug Bridge (adb) is a command-line tool that lets you communicate with a Android device. It facilitates a variety of device actions, such as installing and debugging apps. There are several other facilities that adb provides. For more information about adb, visit here.
How adb works?
When you start an adb client it locates the connected devices (emulator or actual device connected through USB). Once the devices are located, you can run the adb commands to control those devices. adb is included in the Android SDK Platform-Tools package (if you’ve Android Studio installed). You can download this package with the SDK Manager, which installs it at android_sdk/platform-tools/. Or if you want the standalone Android SDK Platform-Tools package, you can download it here.
How to run adb commands?
Considering you have Android Studio installed in your Mac, you have two ways to run adb commands –
To be able to run adb commands directly from any directory in the terminal, perform the following steps –
- Run emacs ~/.bash_profile command on your terminal. This will open your bash_profile.
- Add this line to the file – export PATH=”$PATH:/Users/user-name/Library/Android/sdk/platform-tools”. Make sure you replace user-name with your Mac username (Home directory name)
- Save and Close the EMac editor with CTRL+x CTRL+c. This will ask you to save any unsaved changes. Type y to save the changes.
- Run source ~/.bash_profile to reload your bash_profile.
What you’re doing here is you’re changing the global PATH variable to the platform_tools path. The system will use this path to run all the adb commands. You can now run any adb command in your terminal.
If you don’t want to set the global PATH variable, you must be in the paltform_tools folder on your terminal to run adb commands. The adb executable is generally found at ~/Library/Android/sdk/platform-tools
Now onwards, make sure you prefix all the adb commands with ./
For eg: ./adb devices
You may get an error saying adb command not found. The above setup should resolve your issue. If you still face the same problem, refer to this Stack Overflow link and follow the approaches mentioned by the people.
How to install apk on your device/emulator using adb command?
- Run adb devices command on your terminal. This command prints all the connected devices and emulators with your Mac. Here is the sample data printed by this command –
- You get a serial number of the device along with its status (offline/device/no-device). In the above example, G070VM0583750P7T is the serial number of my Fire TV. You can also run adb devices -l to get more info about the connected devices.
- Run adb -s <serial_number> install <apk_path> to install your apk on the device. Make sure you replace <serial_number> with the actual serial number of the device printed by adb devices command. Also <apk_path> should be replaced by the local path of your apk.
- If you have only one device/emulator connected to your Mac, just run adb install <apk_path>. This will install the apk on the only connected device.