How to install and use Android Debug Bridge (ADB)?



Android Debug Bridge (ADB) is an effective command line tool that makes establishing a connection between a computer and phone smooth with the help of various commands. You can communicate with the device smoothly and perform various tasks like assessing the Unix shell to run commands, debugging apps, and many more.

Read this informative piece by the developers of an Android app development company and establish an effective and easy connection between your PC and your phone with the help of ADB commands.

What is Android Debug Bridge?

Android Debug Bridge (ADB) is a command-line tool that facilitates communication between computers and Android devices. Developers can interact with a connected Android device or emulator for various debugging purposes such as installing, debugging apps, accessing system files, transferring data, and running shell commands on the device with the help of ADB.

It is a bridge between the developer’s computer and Android device enabling diagnostic operation and control over the functionalities of a device from the command line or through graphical interfaces like Android Studio.

When businesses hire Android app developers they ask many questions to find whether the developer is the right fit for the project or not. They can also include questions related to ADB and ask developers. It will show their knowledge related to software and hardware development.

There are three main components of the Android Debug Bridge.

1) Client:

When you as a client send a command to run on an Android device, the ADB command helps the client from the ADB command-line tool.

2) Daemon:

Daemon runs commands on a device. It works as a background method on each device.

3) Server:

The server handles communication between the client and the daemon. It runs as a background method on your Android phone.

Looking for experienced developers for your dream project_

How does Android Debug Bridge work?

As you start the Android Debug Bridge client, it first checks whether there is an ADB server processing already running or not. The confirmation is crucial to start the process. Start the server process if there is no ADB server processing running. As the server starts, it binds to the near TCP port 3057 and listens to commands sent from adb users.

Note: All ADB clients port 5037 to communicate with the adb server.

All the running devices connect with the server in a short time. The following points explain the ADB functionality.

  • Connection establishment:

You as a developer connect an Android device or an emulator to a computer via USB or over a network

  • ADB daemon on the device:

The Android device has an ADB daemon running in the background, which manages communication between the device and the computer.

  • ADB client on the computer:

On the computer side ADB client, a part of the Android SDK sends commands to the ADB daemon on the device. This client is executed through the command line or an integrated development environment like Android Studio.

  • Command execution:

Through the ADB client, developers can execute various commands. These are installing apps, file transfer, debugging, etc. ADB supports Android 11 and Android 12 as well.

  • Response transmission:

The ADB daemon executes the received commands on the Android device and relays back the results or responses to the ADB client on the computer.

This interaction allows developers to perform debugging, testing, and diagnostic operations on Android devices directly from their development environment. It helps developers in building apps and troubleshooting.

How to Install Android Debug Bridge?

There are three methods to utilize adb on your device.

  1. Built-in ADB is present in Android Studio on your machine.
  2. You can download the latest version of the Android SDK platform which includes ADB.
  3. The package manager tool depends on your system. You can also follow this way to use adb.

After installing, verify correctness by typing the “ADB” command.

abc

You can add an ADB path to environment variables and run ADB commands if you notice the command is not recognized. Allow connection with your phone after the successful installation. Now, based on your needs, connect your physical phone using an Android Virtual Device. You can check the documentation section AVDS.

Now you have to check the connection with your device

image

 

Check whether your device is present in the list of devices.

When you see the below types of commands. It means the daemon process is successfully started on a device you connected.

image

You can restart the whole process if you see there is an issue by running the following command.

image

Often, when using Android Studio, your device may not appear on the list of available devices. In this case, you can check all the available options of ADB by writing the below command.

image

Often, it is difficult to find out which one is your device when many devices are connected to the system. In this case, you can specify a unique identifier for the device you want to proceed with.

Use the serial number of your device to pass it as a unique identifier.

The following command shows how to pass the Android device serial number.

image

  • Android Debug Bridge Shell

Android devices operate on a Linux distribution that consists of the Linux Kernel. Please enter the command mentioned below in the command window.

image

It is possible to write and execute Shell commands directly without accessing the shell layer beforehand.

image

Here is an example:

image

It will list all catalogs and files within the sdcard/catalog. Is, touch, and cat are the commands for managing files on your device.

Shell provides many interesting options for dealing with different tasks.

  • Manage catalogs and files
  • Manage application installation
  • Run and stop applications
  • Screen capture
  • Run shell scripts on your device
  • Display and modify system settings
  • File Transfer

The exchange of data between a device and a PC is one of the most powerful features available. Copying data manually is a tedious process. Many other issues come across while working on transferring data manually.GUI windows often fail to display recently created files, making it appear as if the file is missing or has not been given any space.

Android Debug Bridge Pull:

Whenever you want to copy data from a phone to a PC, use the ADB command. This command takes two parameters as shown below.

Android Debug Bridge Pull

Let’s understand the meaning of both parameters.

1) Remote (Required):

It is the path of the file or directory on your phone or any device that you want to download.

2) Local (Optional):

When you download a file, you can specify the local path where the file will be saved. The file will be saved in your current working directory if no local path is provided.

Adding the -P flag to the command lets you check the progress of downloading a file.

Local (Optional)

Android Debug Bridge Push:

You have to push the data from your computer to your phone or device. For this, write the adb push command. It must take two parameters. 

Android Debug Bridge Push

Let’s understand what is “local” and “remote” parameters here.

Local: It is the computer’s local path where you can find files and directories to send them to an Android device.

Remote: The path on your mobile device in a file or directory.

You have to write the –P flag to the command to check the progress of whether the file is uploaded or not.

  • Screen Capture

You can take screenshots and screen recordings using the options available in the Android Debug Bridge. Screen cap shell utility involves screenshots. After assessing the shell layer, add the below-mentioned command.

Screen Capture

 

To take a screenshot on your Android device and save it, use this command. The screenshot will be stored in the Android directory.

Screen recording is also possible via adb. Check the limitations before using it.

  1. No recording in the audio while the video is playing
  2. 3 minutes is the maximum duration of recording
  3. Doesn’t support screen rotation

Use the screen record utility

Screen Capture 1

The presented command below will show available options for screen record utility.

Screen Capture 2

  • Dumpsys

Dumpsys is also a great tool that is available in ADB. This tool runs on an Android device and shows information about the system device.

The following command is to show information for all services.

Dumpsys

You will get to know that the default output by Dumpsys is detailed. It makes the specific command line options necessary.

The below command will show you the listing of all available system services.

Dumpsys 1

We know that many services run on an Android device. Your phone will also have some services. Every service offers its option. You can check them using the below command.

Dumpsys 2

For example:

Dumpsys 3

It will show you the available options for battery service:

available options

  • Activity service

It is used to display the details of activities within your phone. The basic information will be provided about all the activities. There is a con to using the service directly is poor readability.

Here are some key dumpsys services:

1) Dumpsys meminfo:

As the name implies, it provides information about memory usage by applications. It provides detailed memory usage data and allocated objects.

Read More: Best Android app development tools for developers

2) Dumpsys network:

It offers information about network usage by applications. Statistics on data sent are available in this network. Network connection information is received by applications.

3) Dumpsys batteryinfo:

You can know about the battery consumption by individual applications. Monitoring and optimizing energy becomes easy when Dumpsys batteryinfo is used.

Finding out program bugs

Finding bugs in a system is one of the crucial steps to keep the system healthy. To create a bug report use the below command.

Finding out program bugs

What are the benefits of using the adb bugreport command?

1) Easy collaboration:

You can directly share the report with your development team. It leads to effective communication and collaboration, helping in identifying software issues.

2) System information:

It provides a brief report that contains detailed information about the system logs, running processes, network status, battery usage, and more. Diagnosis and troubleshooting become easy with the system information.

3) Bug reports:

Important information like system logs and the state of the device are being executed at the bugreport command.

Want to see more than a 2% conversion rate_ Our developers can help you

What are the steps for interaction with an Android application?

Follow the below actions to interact with the Android application.

  1. Installing and uninstalling applications
  2. Managing app permissions
  3. Launching activities
  4. Simulating events. For example text typing and clicking

How to manage the application installation?

Android Studio provides tools for managing applications. It is important to understand how your app is installed on the device.

Advantages of using Android Debug Bridge commands:

1) Automation:

You can incorporate adb commands into automation tools and scripts. It will help to perform batch operations on various devices

2) Troubleshooting:

You can find and check various error messages from CLI. It helps to deal with different problems.

3) Efficient app installation:

ADB command helps to quickly install Android applications. You don’t have to rely on Android Studio for the same.

Managing app data and permissions

Here is a simple command for clearing the data and cache associated with a package.

Managing app

Granting new permission is another package manager advantage.

Managing app 1Simulate user interactions

Many times, you have to do the same tasks over and over again, especially when creating new UI features. ADB can help developers in such a scenario.

Developers can manage clicking, typing, and swiping events effectively with the help of ADB.

1) Clicking:

Use input tap X and Y commands. Here X and Y represent the coordinates.

Clicking

2) Typing:

Text input is significant in an Android device. ADB offers an input text command. It allows to enter text directly.

typing

What are the key events?

When physical and virtual keys drive events important for Android devices, they are considered key events. These events are crucial for user interaction with the hardware and software.

Here are some common key codes present on Android devices:

  1. Keycode-HOME- Associated with the home button
  2. Keycode-MENU- Associated with the menu button
  3. Keycode-BACK- Associated with the back button

What is Scrcpy?

Scrcpy is an important ADB library. Developers use this powerful and efficient tool for various projects. It helps in mirroring and controlling the device’s screen from your computer. Screen mirroring is one of the powerful features of the Scrcy library.

Did you know that you can display your Android device screen on your computer? This is possible through screen mirroring. This technology is widely used across the globe and has become popular. People use it to give presentations and share important information on a larger screen with high resolution. Developers can also use it to demonstrate apps and record videos.

Screen mirroring command:

Scrcpy

You can use the -S flag to check whether other devices are connected or not. It lets you add additional parameters.

  • max-size <resolution>
  • stay-awake
  • bit-rate <bitrate>
  • show-touches
  • no-control
  • record file .mp4

Conclusion

Developers can interact with Android devices effectively with the help of the Android Debug Bridge command-line tool. It serves as a robust tool offering a diverse array of commands and facilitates developer’s interaction with Android devices. The extensive toolkit for debugging assists developers in automating various tasks of testing and debugging. Familiarize yourself with the several commands used in ADB and establish a better connection between your PC and Phone.

Want an app rich in security features for your customers_

tn_author_image

Mr. Sanjay Singh Rajpurohit, An early-aged entrepreneur who always leads his team from the front and achieved success. As the founder & CEO of Technource, a top mobile app & Web development company, he made a global presence in a short time by offering custom software development, premium mobile apps, and website development services to global clients. In his free time, he loves writing. He is featured on Hackernoon, Dzone, Enlear Academy, Articlesfactory, and much more websites.

[contact-form-7 id="13581" title="Contact Form Footer"]

Offices