Commonly used ADB commands

Source: Internet
Author: User

In peacetime work, will often use the ADB command, here a little to tidy up a bit. The title may be changed to "My usual adb command" perhaps more precisely. Anyway, get in the chase.

I. Summary

1. What is ADB?

ADB is all called the Android Debug Bridge, is to play the role of the Debug bridge. Through the adb we can easily debug the Andriod program through DDMS in Eclipse, which is the Debug tool. ADB has a special way of working, using ports such as the socket TCP 5554 to communicate with the IDE and QEMU, by default ADB will daemon the associated network ports, so the ADB process will run automatically when we run eclipse.

2.ADB Working principle

Not very understanding? Then take a look at how it works.

is a simple working schematic of the ADB. The ADB itself is a client server application consisting of three components: Client,server,daemon.

When you start an ADB client (client), the client first confirms that an ADB server (server) process is already running. If not, the service process is started. When the server is running, the ADB server binds to the local TCP port 5037 and listens for commands from the ADB client.

The server then establishes a connection to all running emulators or device instances. It locates all simulators or devices by scanning all odd ports within the range of 5555 to 5585. Once the server has found the ADB daemon (daemon), it will establish a connection to that port. Note that any emulator or device instance will get two consecutive ports: an even port is used for the corresponding console connection, and an odd port is used to respond to the ADB connection.

Once the server is connected to an emulator/device instance, you can use the ADB command to control and access the instance.

The role of 3.ADB

With the ADB tool, we can manage the status of the device or phone simulator, as well as many phone operations, such as installing software, upgrading the system, running shell commands, and so on. In short, the ADB is a bridge between the Android phone and the PC, allowing users to fully operate their phones on their computers.

Two. Common commands

This part of course is about how ADB is used.

1. ADB devices

View the currently connected device (the Android device or emulator that connects your computer).

2.ADB Install

ADB install the <apk file path, the APK installed will be placed in the/data/app directory.

Several parameters:

-R Forced installation

-D (True, only one true machine in multiple devices applies)

-E (emulator, available in multiple devices with only one emulator)

-S (Specify device, followed by serial number)

Adb–s 44a188f9 install–r test.apk (where 44a188f9 is the serial number, accessible via ADB devices)

3.ADB Uninstall

ADB uninstall <APK Package name >

ADB uninstall–k <apk Package name >

-k parameter preserves configuration and cache files when uninstalling software

4.ADB reboot

Restarting the device

5.ADB Shell

With the adb shell command, you can go into the shell environment of the device or simulator, and in this Linux shell we can execute a variety of Linux commands.

If you want to execute only one shell command, you can use: adb shell [Shell_command]

Often used with grep or findstr, it acts as a filter.

6.ADB Shell Su

The premise of the phone is root. Gets the root permission of the ADB shell.

With the SU right, the user command prompt has $ into #, if the phone does not have root, will prompt su:permission denied.

7.ADB Shell Ps/top

View process information in the current terminal, such as PID

8.ADB Shell AM/PM

AM is all called activity Manager, using AM to simulate the behavior of various systems, such as to start an activity, force stop process, send broadcast process, modify device screen properties, etc.

such as: ADB shell am Start <apk package name >/<activityname>: Start an activity.

PM is all called Package Manager, using PM commands to simulate Android behavior or query apps on your device.

Example: ADB shell PM List Packages

Lists the package names of all installed programs for the current device.

More detailed information can be found in reference 3 and reference 4.

Description

Pipe symbol "|" : You can combine a standard input stream with a standard output stream, or a standard output stream of a command as a standard input stream for another command. Exit the shell.

Because grep is a Linux command, running a single adb shell does not go into the Linux shell environment, and cannot be used with other Linux commands such as grep, only with window cmd commands.

Here you can use findstr instead of grep, using findstr [keyword]

For common Linux commands and common Windows console commands, see also.

9.ADB Pull and adb push

ADB pull <remote> <local>: Copy files from emulator or device to local.

ADB push <local> <remote>: Copy the local file or directory to the emulator or device.

10.ADB Shell Dumpsys

The Dumpsys tool provided by Android is used to view information and status of system services of interest.

Refer to the following table:

11.ADB Shell Monkey

Run Monkey is a means of automated testing of Android, Monkey test itself is very simple, is to simulate the user's key input, touch screen input, gesture input and so on. When the monkey program is running in a simulator or device, it generates random pulses when a user clicks, touches, gestures or some system-level event, so you can use monkey to load test your software with a random, repetitive approach.

Description: The first-s specified device, if only one device is connected, can be omitted.

-P <APK Package name > only allows the system to start the specified app, if not specified, will allow the system to boot all apps in the device, or multiple packages can be specified.

--throttle < milliseconds > Specifies the delay between user actions (events).

--ignore-crashes specifies that when an application crashes, monkey still sends events until the event count is complete.

--ignore-timeouts when an application has a ANR error, monkey still sends the event until the event count is complete.

2nd-S, which specifies the seed value of the pseudo-random number generator, and if seed is the same, the sequence of events produced by the two monkey tests is the same.

-V is used to specify the level of feedback information (the level of information is the verbosity of the log), with a total of 3 levels. Level 0 1 2, where level 2 description is the most detailed log, including the selected/unchecked activity information in the test.

The last number (here is 500) indicates that the monkey program simulates 500 random user events.

> Output test results to D:\monkeylog.txt

More detailed parameters can be seen in reference 5.

Some of the test results are as follows:

12.kill

How to force shutdown monkey, you can use the kill <monkey process pid>

Description: Open another cmd, find the PID number of monkey, and then kill it.

Reference documents:

1.Android Debug Bridge: http://www.iteye.com/topic/260042

2.Android Profiling Tools Dumpsys use: http://www.open-open.com/lib/view/open1405061994872.html

Am PM Command in 3.adb Shell: http://www.android100.org/html/201312/09/4957.html

4.ADB Shell How to start an application: http://blog.chinaunix.net/uid-26997997-id-3350449.html

5.Monkey pressure test Detailed: http://blog.csdn.net/huangbiao86/article/details/8490743

Commonly used ADB commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.