ADB Commands



ADB Commands

In this tutorial we will learn what is an ADB and how we can issue adb commands from command line or from a testing script. Following will be covered in this chapter:

  1. How to print the adb version number
  2. How to print a list of all attached devices/emulator instances to adb server.
  3. How to install an apk file to an emulator/read android device
  4. How to capture logs of android device
  5. How to start and terminate adb server
  6. How to starts a remote shell in the target emulator/device instance.
  7. How to push a file (.txt/.pdf/.jpg/.apk ) to a device/emulator
  8. How to pull a file (.txt/.pdf/.jpg/.apk ) from a device/emulator to local machine
  9. How to redirect adb command to a specific device.

 

ADB : ADB stands for Android Debug Bridge. It is a command line tool that lets us communicate with an Android device or an Emulator. It is a client-server program that includes three components:

  • A client, which runs on our machine. We can invoke a client by issuing an adb command.
  • A daemon, which runs as a background process on each emulator or device instance. It by default runs on port number 5037
  • A server, which runs as a background process on our machine. It manages communication between the client and the adb daemon running on an emulator or device.

 

This tool can be found in Android ADB bundle which we can download from hereThe location of adb tool is Android >> android-sdk >> platform-tools >> adb:

adb_Command_0

Most Commonly used ADB Commands

 

How to print the adb version number?

Command Syntax: adb version
This command prints the adb version number
adb_Command_1

 

 

How to print a list of all attached devices/emulator instances to adb server?

Command Syntax: adb devices
This command prints status information of all the attached devices.

adb_Command_2

This displays the information in the format:

Serial Number   State
6a2ed0b            device

Serial Number: A string created by adb to uniquely identify an emulator/device
State: The connection state of the instance. It can be offline, device, no device

  • Offline : The device is not connected or not responding
  • device : The device is connected to adb server
  • no device : There is no device connected to adb server

Take a look at the above screenshot, adb device command is fired three times and the result is different at each time.

First Attempt: It displayed two devices attached, out of which one is real device and another one is Emulator running on the machine. 

Second Attempt: Again it displayed two device but this time the Emulator is showing as Offline state, as I switched it off.

Third Attempt: In the last attempt it is not displaying anything, as I detached the attached device and shutdown the running Emulator on the machine.

 

How to install an apk file to an emulator/read android device?

Command Syntax: adb install <local_path_to_apk>

This command will install the apk file to attached device / emulator
adb_Command_3

Note: Emulator should be up & running before firing adb install command. In the above screen shot emulator-5554is displayed with device status, it means it is up & running.
Note: I got one Amazon APK file placed at C:\Apps\Amazon.

Once done, notice that the Amazon app will display in the Emulator screen.

adb_Command_4

How to capture logs of android device?

Command Syntax: adb logcat
This command will print the logs data to the screen for the purposes of bug reporting. We can also store these logs into local file using below command:
Command Syntax: adb logcat > <local_path_to_text_file>

adb_Command_5

A log file will be created at the given location.

adb_Command_6

 

How to start and terminate adb server?

Command Syntax to Terminate Server: adb kill-server
This command terminates the adb server.

adb_Command_7

Command Syntax to Start Server: adb start-server
This command checks whether the adb server is running and starts it, if not running.
adb_Command_8

 

 

How to starts a remote shell in the target emulator/device instance?

Command Syntax: adb shell
adb_Command_9

ADB provides a Unix shell that can be used to run a variety of commands on an emulator or connected device. The command binaries are stored in the file system of the emulator or device. The following commands can be executed on shell:

Command Syntaxgetprop ro.product.model
This command get’s the attached device model no

Command Syntax: getprop ro.build.version.release
This command get’s the android build release version i.e. 4.4.2/4.4.4

Command Syntax: getprop ro.build.version.sdk
This command get’s the device api version i.e. 19,20,21,22
adb_Command_10

 

Command Syntax: pm list packages –f
Using pm (package manager tool) we can perform actions and queries on app packages installed on device. E.g. we are listing all packages with path of their associated file.
adb_Command_11

Note: Here pm is a tool and list package is a command and –f is an option to list path of file associated with package.

 

The above command can also be utilized to print the package of installed apps. E.g. Android browser’s app package can also be printed with this which is installed on the device.

Command Syntax: pm list packages –f | grep “chrome”
Command Syntax: pm list packages –f | grep “mozilla”
adb_Command_12

 

Command Syntax: pm uninstall <app Package Name>
This can be used to uninstall an app using pm tool as per above mentioned command.
adb_Command_13

Step 1: To get the package for Amazon app
Step 2: Uninstall Amazon Package
Step 3: Again to get the package for Amazon app, this time it will not displayed anything, as Amazon app is now uninstalled from the device, please refer the below screenshot.

adb_Command_14

 

 

How to push a file (.txt/.pdf/.jpg/.apk ) to a device/emulator?

Command Syntax: adb push <local_Path_of_file> <remote_Path_where_file_to_be_copied>

Let’s see  how to do this. First it is required to start a remote shell in the target emulator/device instance and find remote path to copy the file. E.g. To copy the file to sdcard

  1. ls -l | grep “storage” – List files/directories with name storage
  2. cd storage – Changed current directory to ‘storage’
  3. ls -l | grep “sdcard” – List files/directories with name sdcard
  4. cd sdcard1  Changed current directory to ‘sdcard1’ = storage/sdcard1
  5. ls -l  – List all the files/directories in sdcard1
  6. pwd – See current path, this is remote path

adb_Command_15

adb_Command_16

Now the command to push the Amazon apk fill be: adb push C:\Apps\Amazon\in.amazon.mshop.android.shopping.apk /storage/sdcard1

adb_Command_17

 

How to pull a file (.txt/.pdf/.jpg/.apk ) from a device/emulator to local machine?

Command Syntax: adb pull <remote_Path_of_file_on_device> <local_Path_where_file_to_be_copied >

 

How to redirect adb command to a specific device?

If multiple emulators are running and/or multiple devices are attached and if perform adb shell command. This command returns an error if more than one devices are attached. Refer the below screenshot for Step 2.

-d, -e, or -s options can be used to specify the target device to which the command should be directed.
Command Syntax: adb -s <deviceName> <command>

Direct an adb command a specific emulator/device instance whose deviceName is passed.

adb_Command_18

 

Command Syntax: adb –d <command>
Directs adb command to the only attached USB device.

Command Syntax: adb –e <command>
Directs adb command to the only attached Emulator.
adb_Command_19

Tags: , , , , ,
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!

https://bridgejunks.com/ https://crownmakesense.com/ https://brithaniabookjudges.com/ https://hughesroyality.com/ https://rhythmholic.com/ https://bandar89.simnasfikpunhas.com/ https://www.100calshop.co.il/products/thailand/ https://myasociados.com/ https://solyser.com/ http://konfidence.cz/ https://muscadinepdx.com/ https://bandar89.parajesandinos.com.ve/ https://goremekoop.com/ https://oncoswisscenter.com/ https://www.turunclifehotel.com/bandar89/ https://www.houseofproducts.biz/ https://taimoormphotography.com/
BIJI18 BIJI18 BIJI18