Installing Android apk using adb

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 –

  1. Run emacs ~/.bash_profile  command on your terminal. This will open your bash_profile.
  2. 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)
  3. 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.
  4. 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 –

G070VM0583750P7T device
emulator-5554 device

  • 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.

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.