1. Introduction to ADB
Abbreviation: ADB
Full English name: Android Debug Bridge
Full Chinese name: Android debugging bridge
Function: Tools for communicating with Android devices
2. Install ADB
adb is included in the Android SDK platform tool package. You can useSDK ManagerDownload this package and the manager will install it under android_sdk/platform-tools/.
Or, if you need a standalone Android SDK platform tool package,You can click here to download。
III. Environment variables
Different configuration methods for Windows, Mac, and Linux can be searched on Baidu or Google according to the corresponding platform. Due to limited space, this article is omitted
4. Connect to the real machine
1. Enable developer options
Tap the version number 7 times in a row (Settings > About Phone > Version Number)
2. Enable USB debugging
Developer Options > USB Debugging
3. Enable file transfer
Change USB charging mode to file transfer
4. Mobile RSA key authorization
A dialog box pops up in the device and must be manually determined to perform USB debugging and other adb commands.
5. Commonly used commands
View the ADB version
adb version
Help Information (Important)
adb --help
or
adb help
or
adb
ADB's help information is described very comprehensively. Learn to view the help information of command line tools, and achieve twice the result with half the effort.
Open the ADB server
adb start-server
Close the ADB server
adb kill-server
Check the device connection
Brief information: adb devices
Details: adb devices -l
Install the App
Normal installation: adb install
Reinstall, keep data uncleared (overwrite installation): adb install -r
Allow debug package installation: adb install -t
Authorize the runtime permissions of the file and install: adb install -g
Push multiple apks to the device, install as one package: adb install-multiple
Uninstall the App
Normal uninstall: adb uninstall .package_name
Keep data uninstalled: adb uninstall -k .package_name
Push file
Push from native to Android device: adb push local remote
local represents the path to the local file
remote means the path of an Android device
Pull File
Pull to the local machine from an Android device: adb pull remote local
remote represents the path of the file or directory of the Android device
local represents the path to a native file or directory
View log
adb logcat
6. Advanced skills…
Specify 1 or n of multiple devices
adb devices command or adb devices -l get the serial number of all devices
1. adb -s serial number command... For example: adb -s dasdfew123 install
or
1. ANDROID_SERIAL environment variable, which can specify the sequence number of a single device
2. ANDROID_SERIAL environment variable can specify the serial numbers of n devices, using comma "," as the separator
When not specifying the serial number, adb will read the value of the ANDROID_SERIAL environment variable
Use -s and ANDROID_SERIAL environment variables at the same time, then -s will overwrite the value of ANDROID_SERIAL environment variable
WLAN connection
Prerequisite: The mobile phone and PC are on the same LAN (under the same WLAN)
Principle: The adb server on the PC establishes a TCP connection with the adbd process on the Android device
How to establish a connection?
1. Connect your phone and PC via USB
adb tcpip 5555
After running, the adbd process on the Android device will start listening for port 5555 (in Listener state)
2. Unplug the phone from the USB connection
adb connect <mobile IP>
After running, the adb server on the PC establishes a TCP connection with the adbd process (listening to port 5555) on the Android device.
How to disconnect WLAN connection?
adb disconnect
How to switch WLAN connection to USB connection of Android device?
adb usb
Bluetooth connection
... ...temporary
Port Forwarding
……temporary
7. Advanced Unix command line tools (Android is based on Linux kernel)
View available commands for Android devices (Important)
adb shell ls /system/bin
Enter the device shell
adb shell
Execute any available commands
(All commands listed in adb shell ls /system/bin can be used)
top
ps
dumpsys
am
input
Wait... various commands... to be continued
8. Commonly used Unix command line tools
Check the process status: ps
Check the CPU status: top
System Service: dumpsys
9. ADB principle
Adopt client/server architecture (C/S architecture)
Consisting of 3 processes
1. ADB client process
Run on the PC, used to send commands, is the CLI client, started on the command line, the command run ends, and the process ends with the end
2. ADB server process
Running on a PC, it is started by the ADB client, responsible for communicating with the adbd process on Android devices and the ADB client process on PC; the ADB client on PC communicates with the adbd process on Android devices, and it is entirely forwarded by the ADB server process on PC...
3. Adbd process
Run on an Android device and is responsible for communicating with the ADB server process on the PC
Process communication method
1. ADB client and ADB server
Both the ADB client and the ADB server are running on the PC and use TCP to establish a connection, namely Network Socket
2. ADB server on PC and adbd process on Android devices
Use USB cable to establish connection (default)
or
Use TCP to establish connection (wireless adb)
Process life cycle
1. The life cycle of the ADB client process
Enter any adb command in the command line and create the ADB client process. After the client's command execution is completed, the adb client process will be destroyed naturally
2. Life cycle of ADB server process
Called by any client (such as adb command line, Android Studio, etc.), resides in the PC's memory, as a daemon
3. The life cycle of the adbd process
The init process reads the file (the file contains the configuration information of the adbd process), and then forks the adbd process. The adbd process is created after the Android system is started. It is always running in Android memory and serves as the daemon of the Android device.
Port 5037
1. When starting any ADB client (Android Studio, command line tools, etc.), the ADB client will check whether the ADB server process is running.
2. If the ADB server is not running, the ADB client will execute the code to start an ADB server process.
3. After the ADB server is started, it will be bound on the local 5037 port (TCP port) of the PC to listen to the commands issued by all ADB clients. All ADB clients communicate with the ADB server through TCP port 5037.
10. Little secret
I discovered a secret. After closing Android Studio on Mac, the ADB server process (adb server) will definitely be killed. If you don’t believe it, try it...
References:
/studio/debug/dev-optionsConfigure developer options on the device
/studio/run/deviceRunning applications on hardware devices
The above is the detailed introduction of the installation and use skills of the super detailed Android debugging tool ADB. For more information about the introduction of Android debugging tool ADB, please pay attention to my other related articles!