Overview
ADB as a tool for interacting and communicating with PC and Android devices
Android Debug Bridge, Android Debugbridge, it is a CS Architecture command-line tool, the role of the PC through the ADB to operate the phone
The composition of the ADB
Client: All commands are PC-initiated and can be installed, uninstalled, and debugged for Android apps (multiple windows or programs can send commands)
Server: Manages the client's connection to the ADB background process on the Android device (commands from different clients are owned by the server and the Android device communicates with each other via a 5037 port connection)
Daemon: Android Background running process, responsible for receiving commands (ADB server and daemon communication is implemented through the adjacent two ports, even-numbered ports (such as 5554) is responsible for processing command line communication, odd ports (such as 5555) is used to maintain the connection, we can see, ADB server can be connected with more than one device, each connection, will be allocated two adjacent ports out, the first pair is 5554/5555, the second pair is 5556/5557, the corresponding, when we are connected to more than one device adb, need to specify the port number or device name, the server will find the corresponding device, for communication)
ADB environment configuration
Download the SDK-------Configure tools and platform-tools two directories into the system environment variable path-----so that you can verify it directly at the command line using the ADB command.
ADB command ADB basic command format
adb [-e |-d |-s< device serial number >]< sub-command >
Parameters |
Description |
-E |
Run only in emulator adb-e shell |
-D |
Run only on the real machine adb-d shell |
-S |
Run on the specified device, the device serial number is obtained through ADB device |
Help |
List adb Help files |
Version |
List adb versions |
ADB Basic command
File transfer and Installation commands
Sub-command |
Parameters |
Description |
Devices |
[-l] More information |
List all connected devices in three states Device/offline/device not Fount The device is connected properly, the device is disconnected and the device is not found. |
Push |
<local> <remote> |
Copy your computer's local files to your mobile device |
Pull |
<remote> <local> |
Pull phone device files to local |
Install |
[-LRTSD] <file> |
Install APK -L: Identity app as restricted app -R: Replace installation -T: Run the Install test package -S: Install to SD card -D: Allow downgrade installation |
Install-mutiple |
[-LRTSD] <file ...> |
Batch Installation -P: Partial Application Installation |
Uninstall |
[-K] <package> Find package name can be via command (ADB shell pm List Packages | find "* * *") |
Unloading -K: Keep files under Data and cache |
Get Info command
Sub-command |
Parameters |
Description |
Wait-for-device |
No |
Wait for device to connect |
Start-server |
No |
Open ADB Service |
Kill-server |
No |
Kill the ADB service (you can try when the ADB is not connected) |
Get-state |
No |
Get ADB Service Status Offline | bootloader | Device |
Get-serialno |
No |
Get SN number |
Get-devpath |
No |
Get Device-path |
Status-window |
No |
Continuous printing of device status for specified devices (listening status)-use more when doing development tools |
Log and restart related commands
Sub-command |
Parameters |
Description |
Bugreport |
No |
Print the output of the current Dumpsys,sumpstate,logcat |
Logcat |
More parameters, Need to study separately |
Output Android System log |
Shell |
More parameters, Need to study separately |
Go to the remote shell side |
Remount |
No |
Re-mount the system partition, yes the system partition is re-writable (more for push to the system directory before) |
Reboot |
[bootloader | recovery] |
Restart |
Reboot-bootloader |
No |
Reboot to Bootloader |
Root |
No |
Reboot adbd Get root identity |
Usb |
No |
Restart the ADBD to listen for USB, the equivalent of reseating the USB |
Tcpip |
<port> |
Restart ADBD to listen for the specified TCP port |
ADB Backup and Restore command
Sub-command |
Parameters |
Description |
Backup (writes a page of data file to the specified file, if the-F output directory is not specified, the Backup.ab in the current directory is saved) |
[-f<file>] |
Specify the backup directory |
[-apk |-noapk] |
Whether to back up the APK file, default to No |
[-obb |-noobb] |
Whether to back up OBB packets, default to No |
[-shared |-noshared] |
Whether to back up the SD card share content, default to No |
[-all] |
Back up all installed apps |
[-system |-nosystem] |
Whether to back up system applications,-all including system applications |
[<packages...>] |
Back up the specified list of apps |
Restore |
No |
Restore the backup file to your phone |
These two commands enable data backup and data recovery between two phones.
The procedure can be a full backup of the phone, the backup process can be encrypted, so that the recovery will require a password
ADB redirection Port command
Port mapping Model
REDIRECT the port (1314) on the development PC to the device's port (5200) so that all data destined for PC port 1314 will be forwarded to device port 5200.
This mechanism enables remote control of Android device applications.
Such as
The following form of the specific order, the application of the follow-up if used to supplement
Sub-command |
Parameters |
Description |
Forward--list |
No |
List all socket connections |
Forward |
<local><remote> |
REDIRECT Port |
Forward--norebind |
<local><remote> |
REDIRECT port, fails if local port is already occupied |
Forward--remove |
<remote> |
Remove a locally connected socket |
Forward--remove-all |
No |
To remove all locally connected sockets |
Reverse--list |
No |
List the reverse connection sockets for all connected devices |
Reverse |
<remote><local> |
Reverse Connect sockets |
Reverse--norebind |
<remote><local> |
Reverse connection, failed if port is occupied |
Reverse--remove |
<remote> |
Remove a specific reversal socket connection |
Reverse--remove-all |
No |
Remove all specific reversal socket connections |
ADB wireless connection and file synchronization
ADB wireless connection can not use USB to directly debug Android device, so that is the TCP/IP connection to operate the device, in fact, and the principle of Operation simulator is consistent
Sub-command |
Parameters |
Description |
Connect |
|
Connect to the device via TCP/IP and use 5555 as the default port if no port number is specified |
Disconnect |
|
Disconnect the TCP/IP device, if no port number is specified, use 5555 as the default port, if you use this command without additional parameters, port all connected TCP/IP devices |
Sync |
[<directory>] |
As long as the file changes, it will be automatically copied from the host to the device, you need to specify the environment variable android_product_out to synchronize the directory |
Synchronization of the use of the file is more than a number of so files need to be synchronized, if you delete and push words will be a lot of work, this time using synchronous command
Wireless connectivity and synchronization of specific operations to complement the next improvement
ADB connectivity issues adb list of devices attached
Windows:
Install the driver first, see if the Device Manager driver is installed successfully, cannot install the driver can be solved by a phone assistant
Then turn on USB debugging in the phone developer options and allow the PC to always debug the phone usb
First restart ADB with adb kill-server and adb start-server, or use the command to see which process is taking up 5037 ports and then release
Reference: http://blog.csdn.net/johnnycode/article/details/7678083
At this time if these are ready to be able to connect properly, our phone serial number should have been written to the. Android hidden directory under Windows Adb_usb.ini file, but still the same ADB list of devices attached, At this time we have to consider the automatic connection to write the ADB device number and our terminal using the ADB for the same path, in the appropriate location to write the correct device number, pro-test effective, remember to add 0x
Reference: http://blog.csdn.net/join_12/article/details/45970717
Ubuntu: And the basic ideas under Windows are consistent, specific methods of operation refer to the following posts:
http://blog.csdn.net/mr_driver/article/details/8449642
Adb Devices Offline
Port preemption, you can refer to the above method to solve
Appium first day of automated testing-basic knowledge