I. Summary
1. What is ADB?
Adb is called Android debugging bridge, which plays the role of debugging bridge. As the name implies, adb is a debugging tool.
2. Working principle of ADB
Don't quite understand? Let's see how it works.
The picture above is a simple schematic diagram of ADB. As can be seen from the above figure, Adb client-server program consists of three main parts: client, server and daemon.
(1) When you start an adb client, the client will first choose to confirm whether there is an adb.
The server process is running. If not, the server process will be started. At this point, adb server will bind local TCP port 5037 and listen to adb.
Commands from the client.
(2) Next, the server will scan all odd ports in the range of 5555 to 5585 to locate all simulators or devices and establish connections with them. Once the server finds it,
AsianDevelopmentBank (same as Asian Development Bank)
Daemon, which will establish a connection to this port, so that we can use adb command to control and access the simulator or equipment. It should be noted here that any simulator or device instance will get two consecutive ports: an even port for the corresponding console connection and an odd port for responding to adb connection.
3.3. The role of the Asian Development Bank
With adb tools, we can manage the status of devices or mobile phone simulators, and also do many mobile phone operations, such as installing software, upgrading the system, running shell commands and so on. In short, adb is the bridge between Android phone and PC, which allows users to fully operate the phone on the computer.
Two. Common command
This section mainly introduces the usage of adb and some common commands.
Setting adb environment: Add the working directory of android sdk to the system environment variable, and you can use adb command.
1.adb device
View the currently connected devices (Android devices or emulators connected to the computer).
2. ADB installation
Adb installation < Apk file path >; , install the specified apk on the device, and the installed apk package will be placed in the /data/app directory.
Several parameters:
-r forced installation
-d (real machine, applicable to the case where there is only one real machine among multiple devices)
-e (Simulator, applicable to the case that there is only one simulator among multiple devices)
-s (specify device followed by serial number)
Adb–s4a188f9 installation–-Rtest. APK (where S4A 188F9 is the serial number, which can be obtained through ADB equipment).
3.adb uninstall
Adb uninstalls & ltApk package name >;
Adb uninstall–k < Apk package name >;
The -k parameter is used to preserve the configuration and cache files when uninstalling the software.
4. ADB restarts
Restart android device
5. ADB Shell
Through adb shell command, we can enter the shell environment of equipment or simulator, and in this Linux shell, we can execute various Linux commands.
If you only want to execute one shell command, you can use: adb shell [shell_command].
In practical use, it is often used in conjunction with grep or findstr to play a filtering role and view the key information you need.
6. ADB Shell su
The premise is that the phone is already root. Get root permissions of adb shell.
When using su to lift the power, the user's command prompt will change from $ to #. If the mobile phone has no root, it will prompt su: Permission denied.
7. ADB Shell ps/top
Check the process information in the current terminal, such as pid.
8. Asian Development Bank Shell am/pm
Am is called activity manager, which can be used to simulate the behaviors of various systems, such as starting an activity, forcibly stopping a process, sending a broadcast process, and modifying the screen properties of devices.
For example: ADB shell am start/<; ActivityName & gt: start an activity.
The full name of pm is package manager, and the pm command can be used to simulate android behavior or query applications on devices.
Such as: ADB Shell pm List Package
Lists the package names of all installed programs on the current device.
Description:
Pipeline symbol' |': You can merge the standard input stream with the standard output stream, or use the standard output stream of one command as the standard input stream of another command.
Exit exits the shell.
Because grep is a linux command, running a single adb shell will not enter linux.
Shell environment, you can't use other linux commands such as grep, you can only use the command of window cmd. Findstr can be used instead of grep here, and the use method is as follows
Findstr/grep[ keywords]
For more details, please refer to References 3 and 4.
For common linux commands and common windows console commands, we will summarize them later.
9. ADB pulls and ADB pushes
Adb la < File path in device >; < local path >; : Copy files from an emulator or device to the local.
Adb pushes < Local file path >; < path in device >; : Copy a local file or directory to an emulator or device.
There is also an authoritative question, which will be introduced in the subsequent blog post.
10.adb shell dumpsys
The dumpsys tool provided by Android is used to view the interested system service information and status.
Please refer to the following table:
1 1. ADB shell monkey
Running monkeys is a means of automatic testing of Android. The so-called monkey test is to simulate the user's key input, touch screen input, gesture input and so on. When the Monkey program runs in the simulator or device, if the user clicks, touches, gestures or some system-level events, random pulses will be generated, so we can use Monkey's random repetition method to do stress tests on apk to test android.
The stability of the app.
The following is a simple example of testing Tencent News apk:
Note: The first s specifies the device. If only one device is connected, this parameter is not needed.
-p & lt; Apk package name >; Only the system is allowed to start the specified application. If not specified, the system will be allowed to start all applications in the device, or multiple packages can be specified.
-throttle < milliseconds > specifies the time delay between user actions (events).
-ignore-crashes specifies that when the application crashes, Monkey still sends events until the event count is completed.
-ignore-times When an ANR error occurs in the application, Monkey will still send events until the event count is completed.
The second -s is used to specify the seed value of the pseudorandom number generator. If the seeds are the same, then the sequence of events generated by the two monkey tests is also the same.
-v is used to specify the level of feedback information. Total * * * is divided into three levels: level 0, 1 level, and level 2. The higher the level, the more detailed the output log.
The last number (500 here) means that the monkey program simulated 500 random user operation events.
& gt output the test results to d: \ monkeylog.txt.
More detailed parameters can be found in reference 5.
Some test results are as follows:
For the analysis of test results, locating errors by searching keywords mainly includes the following four aspects:
1)ANR (not applicable
Response): The program didn't respond. Usually, if the main thread does not process it for more than 5 seconds, an ANR error will occur. Locate key event information by searching ANR keywords. In addition to exporting logs, you can also export the trace.txt file in the /data/anr/ directory to locate and analyze problems. Use > ADB
Pull /data/anr/trace.txt d:\ Export the trace.txt file to drive D.
2) Forced shutdown or other abnormal exit information: locate by searching for fatal keywords.
3) Crash problem: locate by searching for the keyword Exception.
4) After the exception occurs, search the Crash keyword to locate the detailed stack information.
killed
Kill is used to stop a process.
For example, when we are running monkey, how can we forcibly close monkey? You can use kill.
Description: Open another cmd, find the pid number of the monkey, and then kill it.
References:
1.Android debugging bridge: /topic/260042
The use of 2.2. Android performance analysis tool dumpsys:/lib/view/open1405061994872.html.
3.3. am pm command in ADB shell:/uid-26997997-ID-3350449.html.
A detailed explanation of 5.5. Monkey stress test:/huangbiao86/article/details/8490743