adb environment construction and use

adb environment construction and use

what is adb

The full name of ADB is Android Debug Bridage, which serves as a debugging bridge. We can debug Android programs through the ADB tool.

Environmental preparation

Configure java environment

Download the jdk installation package from the official website, install jdk, and configure environment variables (configure the java/bin and jre/bin directories into the PATH of the system variables)

Configure adb environment

Download platform-tools from the official website, unzip it and put the add.exe directory into the system environment variable PATH.

verify

Open the cmd window, enter adb version, and press Enter to display the version number, indicating that the configuration is successful.

Connect devices

Connect emulator–wifi

  1. Open the emulator

  2. Turn on developer mode

  • In settings, click About This Mac, click the version number (native version number or brand version number) several times in succession until "You are already in developer mode, no need to perform this operation"
    Insert image description here

  • Enter developer mode options and turn on USB debugging
    Insert image description here
    Insert image description here

  1. Check if the connection is successful: Show connected devices
zydeMacBook-Air:~ zy$ adb devices
List of devices attached
192.168.56.113:5555	device

The above shows that the connection is successful.

Real device connection

Connect via USB cable

Data cable functions: charging, file transfer, adb driver. It is best to choose the original data cable. If it is a configuration data cable bought from an online shopping platform, it may have fewer functions, for example, it lacks the adb driver function.

  1. Use data cable to connect real machine and PC
  2. Turn on developer mode on real machine
  • How to turn on the developer mode on a real Hongmeng system phone: Settings - About phone - Version number, click the version number continuously. Developer mode has developer options in system and updates. Turn on USB debugging.
  • How to turn on developer mode on Xiaomi phones: Settings-My Device-MIUI Version Number, click the version number continuously. Developer mode has developer options in more settings. Turn on USB debugging.
  1. Use adb devices to check whether the connection is successful

When connecting to a real machine for the first time, adb devices may appear indicating that the device is unauthorized, which means that the mobile phone is not authorized. At this time, when viewing the real machine, the authorization box for whether to allow USB debugging will pop up. Check Always allow the use of this computer for debugging, and click OK. Executing adb devices again will return to normal.

Connect via Wi-Fi

  1. Prerequisites:
  • The mobile phone and computer are on the same LAN

  • Turn off the computer firewall (please Baidu how to turn off the firewall in different systems)

  • Exit anti-virus software

  1. Connect the device through the adb connect command
zydeMacBook-Air:~ zy$ adb connect 192.168.110.121:5555
failed to connect to '192.168.110.121:5555': Connection refused

5555 is the default port for real devices to connect to adb.

When connection refused appears, check the direction and check the connection status of port 5555.

zydeMacBook-Air:~ zy$ adb tcpip 5555
error: no devices/emulators found

It shows that no device is connected to port 5555.

If more than one device/emulator is displayed, use adb disconnect to disconnect first. If other devices are connected, the real machine cannot be connected via Wi-Fi. Disconnect and then try connecting your phone via Wi-Fi. If connection refused is still displayed, please read below.

Solution to adb display connection refused

Reason: adbd is not monitoring network connections

Solution: Open port 5555 of adbd service

First connect the phone with USB and then execute

zydeMacBook-Air:~ zy$ adb shell
HNALA7:/ $ setprop service.adb.tcp.port 5555

Then go to settings and turn off and then on again the "USB debugging" option. Then disconnect the data cable and connect the phone through the adb connection command.

zydeMacBook-Air:~ zy$ adb connect 192.168.110.121:5555
connected to 192.168.110.121:5555

adb basic commands

Common commands

  • adb devices - identify all currently connected devices (must learn)
  • adb logcat - system log capture (must learn)

Mobile terminal testing focuses on crash and anr (no response)

zydeMacBook-Air:~ zy$ adb logcat -v time>/Users/zy/Desktop/logcat0324.txt

After starting the mobile test, use this command and it will record all operations done on the phone and redirect the data to the specified path. -v outputs in log form, time uses time information as the main line.

  • adb install/uninstall——Install and uninstall apk (must learn)
zydeMacBook-Air:~ zy$ adb install /Users/zy/Downloads/App_JCSample2.10.1.apk 
Performing Streamed Install
Success

You can quickly add the path by dragging the apk directly into the command line window.

zydeMacBook-Air:~ zy$ adb uninstall com.juphoon.mmetester
Success

The parameter is the package name. The package name is the unique identification code of the application on the phone.

  • adb pull/push - import and export files (must learn)

Take using this command to capture application running logs as an example:

zydeMacBook-Air:~ zy$ adb pull /sdcard/Android/data/com.juphoon.cloud.sample/files/log /Users/zy/Desktop/log_test
/sdcard/Android/data/com.juphoon.cloud...ed. 2.5 MB/s (6266184 bytes in 2.408s)

Usage: The path where the adb pull log is located is exported to the local path.

Another usage:

After the application becomes unresponsive, the system will output the anr log, which is saved in the traces.txt file in the /data/anr directory of the mobile phone. If the system becomes unresponsive during work, you need to export the traces.txt command locally and submit it to development.

zydeMacBook-Air:~ zy$ adb shell
HNALA7:/ $ cd /data/anr
HNALA7:/data/anr $ ls 
anr_2022-03-03-18-02-33-971

As shown in the picture above, because the traces.txt file is not generated in my mobile phone, the application command is not posted here.

  • adb start/kill-server - start and kill processes
  • adb shell——Enter the android system to execute shell commands (must learn)
  • adb shell am start - start the application
  • adb shell pm - list application package names
    • abd shell pm list packages - View all packages currently connected to the device or virtual machine
    • adb shell pm list packages -s - only output system packages
    • adb shell pm list packages -3 - output all third-party packages
    • adb shell pm list packages -f - output packages and files associated with the packages (installation path)
    • adb shell pm list packages -i - output package and installation information (installation source)
    • adb shell pm list packages "lzy" - Output packages containing filter conditions
    • adb shell pm list packages -e - only output enabled packages
    • adb shell pm list packages -d - only output disabled packages
    • adb shell pm list packages -u - only output package and uninstalled package information (installation source)
    • adb shell pm path packages - locate the system path where the apk is located

The command mentioned above

  • adb version——View adb version number

  • adb connect [ip]:[port]——Connect to the mobile terminal through the network

  • adb disconnect [ip]:[port]——Disconnect the mobile terminal through the network

  • adb tcpip 5555 - start the 5555 port of the tcpip protocol (must be connected to the data line for operation)

  • adb -s device number - specify a device for operation

Guess you like

Origin blog.csdn.net/u011090984/article/details/123896169