Android Tools: ADB

Source: Internet
Author: User
Tags unix domain socket

Android Tools: adb Introductionin Android development, the ADB is a tool that developers often use, which Android developers must master. Android Debug Bridge,android Debug Bridge, referred to as ADB, the tool is located in the <sdk>/platform-tools/directory, its source code is located in <path-to-sourcecode>/ The SYSTEM/CORE/ADB directory is a universal tool for managing the state of the emulator or the real machine. ADB uses the client-server model, which consists of three parts:
    1. Client section, running on a development computer, you can run the ADB command on the command line to invoke the client, and an Android tool like DDMS can also invoke the ADB client.
    2. Daemon section, running in the background of the emulator or phone.
    3. The server-side section is a background process running on a development computer that manages the client's communication with the daemon running in the emulator or the real machine.
The ADB tool model is as follows:How ADB works when you start the ADB client, the client first checks to see if the ADB server process is running, and if it is not running, start the server. When the server is started, it is bound to the local TCP 5037Port, and listens for commands from ADB clients-all ADB clients use 5037Port communicates with ADB server. Next, the server is connected to all running emulators or phones. It searches for an emulator or phone by scanning an odd number port between 5555-5585, and once the ADB daemon is discovered, it connects through this port. It is necessary to note that each simulator or phone uses a pair of ordered ports, an even number port for the console connection, an odd number port for the ADB connection, for example:
Emulator 1, console:5554
Emulator 1, adb:5555
Emulator 2, console:5556
Emulator 2, adb:5557
That is, if the emulator is connected to ADB on port 5555, its connection to the console is 5554 ports. When the server is connected to all the emulators, it can be controlled or accessed using the ADB command. Because the server manages the connection and can receive commands from multiple ADB clients, any emulator or mobile device can be controlled from any client or script. USB Debugging using ADB command debugging requires the phone to turn on USB debugging in developer mode, in Android 4.2 and later, the developer option is hidden by default, you can go to set-up about the phone, then click on the seven-time version number. You can see the developer mode at the bottom by going back to the top. Of course, some custom ROM open mode will be a bit different, this is going to ask the ROM developer.about USB debugging with the computer's RSA key fingerprint pairing. Google's official text reads as follows:When you connect a device running Android 4.2.2 or higher to your computer, the system shows a dialog asking whether to AC Cept an RSA key, allows debugging through this computer. This security mechanism protects user devices because it ensures, USB debugging and other ADB commands cannot is EXECU Ted unless you "re able to unlock the device and acknowledge the dialog. This requires the ADB version 1.0.31 (available with SDK platform-tools r16.0.1 and higher) in order to debug on    A device running Android 4.2.2 or higher. For more information on using real-machine debugging, refer to: Running an app on a hardware device syntaxYou can issue adb commands from a command line on your development, or from a script. The usage is:
adb [-d|-e|-s <serialnumber>] <command>
If there ' s only one emulator running or only one device connected, the ADB command was sent to that device by default. If multiple emulators is running and/or multiple devices is attached, you need to use the-d,-e, or-s option to Specif Y the target device to which the command should is directed. Commands The table below lists all of the supported ADB Commands and explains their meaning and usage.
Category Command Description Comments
< Span style= "line-height:1.6; background-color:transparent; " >TARGET&NBSP, Device -d direct a adb command to the only attached USB device. returns a error if more than one USB device is attached.
-E Direct a adb command to the only running emulator instance. Returns an error if more than one emulator instance is running.
-S <serialNumber> Direct a adb command a specific Emulator/device instance, referred to by its adb-assigned serial number (such as "Emulato r-5556 "). See directing Commands to a specific emulator/device Instance.
General Devices Prints a list of all attached emulator/device instances. See querying for Emulator/device Instances for more information.

Help Prints a list of supported ADB commands.

Version Prints the ADB version number.
Debug logcat [option] [Filter-specs] Prints log data to the screen.

Bugreport Prints Dumpsys, Dumpstate, and logcat data to the screens, for the purposes of bug reporting.

Jdwp Prints a list of available JDWP processes on a given device. You can use the forward jdwp:<pid> port-forwarding specification to connect to a specific jdwp process. For example:
ADB forward tcp:8000 jdwp:472
Jdb-attach localhost:8000
Data Install <path-to-apk> Pushes an Android application (specified as a full path to an. apk file) to an emulator/device.

Pull <remote> <local> Copies a specified file from the Emulator/device instance to your development computer.

Push <local> <remote> Copies a specified file from your development computer to an Emulator/device instance.
ports and Networking forward <local> <remote> port specifications can use these schemes:
  • tcp:<portnum> 
  • local : <unix domain socket name> 
  • dev:<character device name> 

PPP <tty> [Parm] ... Run PPP over USB.
  • <tty>-the TTY for PPP stream. For example Dev:/dev/omap_csmi_ttyl.
  • [Parm]...-zero or more PPP/PPPD options, such as Defaultroute, local, Notty, etc.
Note that you should not automatically start a PPP connection.

Scripting Get-serialno Prints the ADB instance serial number string. See querying for Emulator/device Instances for more information.

Get-state Prints the ADB state of an Emulator/device instance.

Wait-for-device Blocks execution until the device is Online-that are, until the instance is device. you can prepend this command to other ADB commands, in which case adb Would wait until the Emulator/device instance is connected before issuing the other commands. Here's an example:
adb wait-for-device shell getprop
Note The This command does not Cau Se adb to wait until the entire system is fully booted. For this reason, you should not prepend it to the other commands that require a fully booted system. As an example, the install requires the Android Package Manager, which is available only after the system is fully booted. A command such as
adb wait-for-device install <app>.apk
would issue the install C Ommand as soon as the emulator or device instance connected to the ADB server, but before the Android system was fully boo Ted, so it would the result in an error.
Server Start-server Checks whether the ADB server process is running and starts it, if not.

Kill-server Terminates the ADB server process.
Shell Shell Starts a remote shell in the target Emulator/device instance. See ADB Shell Commands for more information.

Shell [Shellcommand] Issues a shell command in the target Emulator/device instance and then exits the remote shell.
Table 1. Available adb commandsadb usage query Simulator or phone status understanding the ADB server-side connection simulator or phone can help you better use the ADB command, which can be used to enumerate the currently connected devices through the devices command:
ADB devices
The result of the execution is that ADB outputs the following status information for each device: 1) Serial number (SerialNumber): A string created by ADB to uniquely identify the device, in the format < device type >-< port number, for example: emulator-5554 2 The connection state, the value of which is probably any of the following:
    • Offline-not connected or not responding
    • Device-indicates that the device is connected to the service side. However, it is important to note that this status does not mean that the Android system is fully up and operational, because the system is connected to ADB during the boot process, but this state is normal and operable.
    • No device– means no device connection (the landlord test process has not encountered no device, no connection equipment, no output)
The output form of each device is as follows:
[SerialNumber] [State]
The following is the ADB devices command and its execution results:
$ adb devices
List of devices attached
emulator-5554 Device
emulator-5556 Device
emulator-5558 Device
If no emulator or phone is running, the execution results of the ADB Devices command are as follows:
$ adb devces
List of devices attached
Operation specified simulator or phone if you have multiple emulators or phones running, you need to specify the target device when using the ADB command, which can be achieved by using the-s option parameter, as follows:
adb-s <serialNumber> <command>
You can use the ADB command to specify the serial number to execute commands on a specific device, where you can first query the device's serial number information using the previously mentioned ADB devices command. For example:
adb-s emulator-5556 Install helloworld.apk
Note that if you use-s and do not specify a device, the ADB will error. If you had multiple devices available (hardware or emulated), but only one was an emulator, and simply use the - eoption to send commands to the emulator. Likewise if there ' s multiple devices but only one hardware device attached, use the - Doption to send commands to the hardware device.
$ adb-e Install helloworld.apk
Similarly, if you have multiple devices but only one, you can send commands quickly using the following command
$ adb-d Install helloworld.apk
Installing an app using the ADB install command to copy an application from a development computer and install it on a simulator or phone, the adb install command must specify the path to the. apk file to be installed:
adb install [-LRTSDG] <path_to_apk>
(-L: Lock the program)
(-R: Reinstall the program to preserve app data)
(-t:allow test packages)
(-S: Installs the app to the SD card, but now the phone doesn't seem to have an SD card.)
(-D: Allow version number to be installed, of course only the debug package can be used)
(-G: All runtime permissions are granted by default after installation, this should be valid for Android 6.0 and later versions)
More about creating APK files can be consulted: Build and running uninstall application since there are commands to install the app, there is certainly a command to uninstall the app. The format of the Uninstall App command is as follows:
//<package> indicates the package name to uninstall the app
adb uninstall [-K] <package>
(-K: Do not remove data and cache directories generated by program runs)
Port forwarding uses ADB forward command forwarding Port-forwards requests on a specific port to different ports on the emulator or phone. The following example goes from Port 6100 to port 7100:
adb forward tcp:6100 tcp:7100
You can also use the UNIX-named socket ID:
adb forward tcp:6100 local:logd
Copying files to or from a emulator/device Instance you can use the ADB commands-pull and push-to-copy Files to and FR Om an Emulator/device instance. Unlike the install command, which only copies an APK file to a specific location, the pull and push commands let you copy    Arbitrary directories and files to all location in an Emulator/device instance. To copy a file or directory (and it sub-directories) from the emulator or device, use
adb pull <remote> <local>
In the commands, <local> <remote> refer to the paths to the target files/directory on your development Mac Hine (local) and on the Emulator/device instance (remote). For example:
adb push Foo.txt/sdcard/foo.txt
For ADB Shell please refer to:ADB Shell CommandsStopping the ADB server in some cases, you might need to terminate the ADB server process and then restart it to Resolv    e the problem (e.g., if ADB does not respond to a command). To stop the ADB server and use the Kill-serverCommand. You can then restart the server by issuing any other ADB command. Wireless usage (slightly) refer to Android tools: Adbandroid Debug Bridge runs on hardware devices application adb Shell Commands

Android Tools: ADB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.