Current location - Music Encyclopedia - Today in History - Technology sharing
Technology sharing
Adb, called Android Debug Bridge, is a tool provided in the Android SDK, which is used to manage Android simulators or real machines.

Adb is a powerful command-line tool, which allows PC to communicate with Android devices. The Adb command can perform various device operations, such as installing and debugging applications.

The client/server (C/S) mode is adopted, which includes three parts:

When the adb client starts, the client will first check whether the adb server is started. Otherwise, the server process will be started first. After the adb server is started, it will bind to port 5037 and listen for commands issued by adb clients.

Then the server will establish a connection with all running Android devices. It searches for Android devices by scanning odd ports between 5555 and 5585. Once the server finds that the adb daemon on the Android device is running, it will establish a connection with the corresponding port. Each Android device uses a pair of ports, even ports are used for console connection and odd ports are used for adb connection.

After the server is connected to all Android devices, you can use adb command to access these devices. The server will manage the established connection and process commands from adb clients.

Android real machine can connect adb through USB. When connecting, you need to enable USB debugging in the system settings of the device (under the developer option). After starting USB debugging, the adb daemon on the device will be started, and the adb server can establish a connection with the device. In addition to USB connection, it can also be connected through WLAN, so I won't go into details.

The content in square brackets is optional, and the content in angle brackets is required. The parameters in square brackets can specify devices, and there are three parameters that can be used to specify devices. -d, -e and -s, where -s is the most commonly used parameter. When connecting multiple devices, -s plus the serial number of the device is usually used to specify a specific device.

Adb can connect multiple devices at the same time, but can only execute commands on one device at a time. When multiple devices are connected, it is necessary to make devices before the command can be successfully executed.

After connecting the Android device to the adb server, you need to confirm the connection status of the device. At this point, you can use the query command to query.

In Windows system, you should first execute the connect command to connect the emulator. 127.0.0. 1 is the local IP address. Because the emulator is installed locally, you should use the local IP address and the port number specified by the emulator itself. The port number of Mu Mu is 7555. If you use another emulator, you need to know its port number before connecting. The connection simulator in MacOS system does not need to execute connect command first, but directly executes adbkill-server &; & ampAdb device command is enough.

The real machine is directly connected to the computer through USB, and there is no need to execute the connect command.

You can directly view the list of connected devices by using the adb devices command.

After the direct command, if the device has been successfully connected, the information of the connected device will be displayed in the device list.

During the test, if you need to install or uninstall the application, you can use the adb command directly.

Adb command supports file transfer between computer and Android device. For example, if you want to extract the log files of Android devices locally, you can do it through adb command.

Print log information of linked devices.

Using the adb shell command is equivalent to logging into the Android system remotely, and you can enter the system of the Android device. Entering the system can not only execute some simple Linux commands, but also support many unique commands.

There are two ways to use the adb shell command.

One is to follow the command directly after adb shell.

For example:

Another method is to start an interactive shell on the device.

After entering the shell, execute the corresponding command.

For example, when you enter the device, you can view the directory structure and content inside the device.

To exit the interactive shell, you can press Ctrl+D or enter exit.

In the test process, if you need to take screenshots or record screens, you can also use adb command directly to complete it.

In adb shell, you can use Activity manager (am) tool to issue commands to perform various system operations, such as starting activities, forcibly stopping processes, and modifying device screen properties.

During the test, if you need to start the app or forcibly close the app, you can do it through adb command.

In adb shell, you can use the package manager (pm) tool to issue commands to perform operations and queries on application packages installed on devices.

If you need to know which applications are installed in the device, you can use adb shell pm list to view them, or you can add different parameters to view different types of applications. You can also use the adb command to clear application-related data.

Dumpsys is a tool that runs on Android devices and provides information about system services. You can use adb to call dumpsys from the command line to get diagnostic output of all system services running on connected devices.

For example, in the test, if you need to start the app through adb command, you need to know the package name of the app and the activity name of the portal. At this point, you can get these two pieces of information through the following command.

In this scenario, you need to start the application to get information, make it run in the foreground, and then execute the command.

Adb shell dump system activity | grep mFocusedActivity

The current package name and activity name are displayed in the log below.

The Adb command also supports direct access to application page information. This page information contains the attributes of the elements in the page, which helps to locate the elements during automated testing. The obtained page layout will be output to an xml file.

If the output file path is not specified, the default storage path of the dumped file is/sdcard//sdcard /sdcard/window_dump.xml

You can transfer files to your computer through the adb pull command, and then use the uiautomatorviewer tool to open and view the layout.

Hello, if you like this article, please click "Like"! Thank you very much ~( ▽) PS: You can contact us if you have any questions ~v ceshiren00 1