Android Automation: ADB

Source: Internet
Author: User

After a period of preparation, starting from today's self-study Android tour, preliminary study will have omissions, I will continue to revise the completion, until perfect.

Google Official Document Connection: http://developer.android.com/tools/help/adb.html

ADB Overview:

Android Debug Bridge,android Debug Bridge, abbreviated as ADB, is a universal tool for managing emulator or real state, using the client-server model, consisting of three parts:

1, the client part , running on the development of the computer, you can run the ADB command on the command line to invoke the client, such as ADB plug-ins and Ddms such as Android tools can also invoke the ADB client.

2, the service side portion , is running in the development uses the computer the background process, manages the client to communicate with the daemon which runs in the simulator or the real machine.

3, the daemon part , runs in the simulator or the handset backstage.

When the ADB client is started, the client first detects whether the ADB server process is running and, if not, starts the server. When the server starts, it binds to the local TCP5037 port and listens for commands sent from the ADB client- all ADB clients use port 5037 to communicate with the 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.

Abd location :

Tool in <sdk>/platform-tools/ . adb

ADB command:

The use of the ADB command from the command line or script file of the development computer is:

adb [-d|-e|-s <serialnumber>] <command>

When used, the program calls the ADB client. Because the ADB client does not need to be associated with any emulator, if more than one emulator or phone is running, you need to use the-D parameter to specify which one to manipulate.

  View ADB version information

  ADB version

  

Query emulator or Phone status

ADB devices

The result of the execution is that ADB outputs the following status information for each device:

Serial Number (SerialNumber)-a string created by ADB using the console number that uniquely identifies an emulator or mobile device, in the format < device type >-< port number, for example: emulator-5554

State-the connection state, whose value is:

Offline-not connected or not responding

Device-has been connected to a service provider. Note that this status does not mean that the Android system has been fully booted up, the system is ready to connect to the ADB, but this state is normal operational status.

The output form of each device is as follows:

[SerialNumber] [State]

The following is the devices command and its execution result:

       $ adb devices       List of devices attached       emulator-5554  device       emulator-5556   device       emulator-5558  device

If no emulator or phone is running, nothing is returned.

start and end ADB services: during the actual commissioning process, there are often connections on the phone but ADB devices can not find the status of the phone, the following command to restart the ADB service

ADB kill-server: End ADB Service

ADB start-server: Start adb service

Install APK

ADB-E Install c:\apps\MyFirstApp.apk When there is only one device:

     

Adb-s emulator-5554 Install c:\apps\MyFirstApp.apk: Installs the APK (real phone is-D) in the specified directory of the specified phone, and returns to success after success.

  

If the input is wrong, an error will occur.

  

Uninstall APK

Method One:

adb uninstall [-K] <package>.

Where the package represents the name of the packages that need to be uninstalled, and K indicates whether to keep the app's configuration information and cache data.

Adb-s emulator-5554 Uninstall Com.example.myfirstapp: Uninstall the program (based on the package name) and return to success after success.

  

Method Two:

Delete manually.
ADB shell
Cd/data/app
RM myfirstapp.apk

  

Then RM com.example.myfirstapp-1.apk, but as if the simulator is not updated in real time, the icon is still in, but when trying to open, will error.

  

Copy apk to SD card

Adb-s emulator-5554 Push c:\apps\esfileexplorer.apk/sdcard/delon/123.apk : Copy apk to sd card (from esfileexplorer.apk copy in C drive directory to SD card with 123.apk name or copy directory)

  

  

Copy apk to Local disk

Adb-s emulator-5554 pull/sdcard/delon/123.apk c:\test\ESFile.apk: Copy apk to Local disk (from 123.apk in SD card to C drive with rename function)

  

  

Remove the set up directory from the SD card

Adb-s emulator-5554 Shell rm-r/sdcard/delon: No hint indicates successful deletion (also deletes all files in the folder)

  

If the deletion fails, prompt:

  

Write to log file:

Adb-s emulator-5554 logcat > C:\info.txt: Writing log information to a file-this is the next Monkey learning phase, in detail.

------------------------is written in the back---------------------------

Do not understand English, and feel that the content of the article is not enough, you can go to see Google documents Chinese translation: http://www.jizhuomi.com/android/environment/191.html

Android Automation: ADB

Related Article

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.