Use of the Android ADB tool

Source: Internet
Author: User
Tags system log unix domain socket

An important command that contains the Android emulator operation under the Tools folder of the SDK Adb,adb is all called Android Debug Bridge, which is the role of the debug bridges, with this tool, we can manage the status of the device or phone simulator, and can do the following:

(1) Quickly update the code in the device or phone simulator, such as app or Android system upgrade;
(2) Run the shell command on the device;
(3) Management equipment or mobile phone simulator on the predetermined port;

(4) Copy or paste the file on the device or phone simulator.

ADB's way of working is a special use of listening socket TCP 5554 and other ports to the IDE and QEMU communication, by default ADB will daemon the relevant network port, so when we run eclipse, the ADB process will automatically run, Debugging Android programs via Ddms in Eclipse, or manually, here are some common actions to refer to.

1. Version Information

D:\UNSETUP\ANDROID-SDK-WINDOWS-1.0_R1\TOOLS>ADB version

Android Debug Bridge Version 1.0.20


2. install the app to the emulator
ADB install [-l] [-r] <file>.

Where file is the decision path for the apk file that needs to be installed.

3. Uninstall an already installed app

(1) Method 1:

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.

(2) Delete manually.
ADB shell
Cd/data/app
RM app.apk


4. Enter the device or simulator SHell
ADB shell
From the command above, you can enter the shell environment of the device or emulator, in which you can execute various Linux commands, and if you want to execute only one shell command, you can do the following:
ADB Shell [command]
Such as:

D:\UNSETUP\ANDROID-SDK-WINDOWS-1.0_R1\TOOLS>ADB Shell DF

/dev:49564k Total, 0K used, 49564K available (block size 4096)

/sqlite_stmt_journals:4096k Total, 0K used, 4096K available (block size 4096)

/system:69120k Total, 65508K used, 3612K available (block size 4096)

/data:76544k Total, 63684K used, 12860K available (block size 4096)

/cache:69120k Total, 1244K used, 67876K available (block size 4096)

5. turn to the originating port

You can use the forward command to forward any port-a specific host port for one emulator/device instance forwards requests to another different port. The following shows how to establish a forwarding from host port 7100 to emulator/device port 8100.

ADB forward tcp:7100 tcp:8100

Similarly, you can use ADB to create a UNIX domain socket interface named abstract, as shown in the following procedure:

ADB forward tcp:7100 LOCAL:LOGD


6. Copying Files

You can use ADB pull, the push command to copy files to a data file for an emulator/device instance, or to copy from a data file. The install command only copies an apk file to a specific location, unlike the pull and push commands, which allow users to copy arbitrary directories and files to any location on an emulator/device instance.

To copy a file or directory from a simulator or device, use the following command:

ADB pull <remote> <local>

To copy a file or directory to an emulator or device, use the following command:

ADB push <local> <remote>

In these commands, <local> and <remote> refer to the path to the destination file/directory on your own development machine (local) and emulator/Device instance (remote) .

Here's an example:

ADB push Foo.txt/sdcard/foo.txt


7. Search for an instance of the simulator/device
Gets a list of instances of the currently running emulator/device and the status of each instance, such as:

D:\UNSETUP\ANDROID-SDK-WINDOWS-1.0_R1\TOOLS>ADB devices

List of devices attached

ht843gz03305 Device


8. View bug reports

D:\UNSETUP\ANDROID-SDK-WINDOWS-1.0_R1\TOOLS>ADB Bugreport

========================================================

= = Dumpstate

========================================================

------SYSTEM LOG------

04-12 16:59:46.521 D/showtrack (23968): Myoverlay::d ARW. Mdefcaption=i ' m here.

04-12 16:59:46.531 D/showtrack (23968): Myoverlay::d ARW. Mdefcaption=i ' m here.

04-12 16:59:46.531 D/showtrack (23968): Myoverlay::d ARW. Mdefcaption=i ' m here.

04-12 16:59:46.541 D/showtrack (23968): Myoverlay::d ARW. Mdefcaption=i ' m here.

04-12 16:59:47.391 I/activitymanager (in): Starting activity:intent {comp={com.iceskysl.itracks/com.iceskysl.itracks . Itracks}}

04-12 16:59:47.641 d/itracks (23968): Renderlistview.

04-12 16:59:47.671 D/showtrack (23968): Myoverlay::d ARW. Mdefcaption=i ' m here.

04-12 16:59:47.681 D/showtrack (23968): Myoverlay::d ARW. Mdefcaption=i ' m here.


9. record the wireless communication log
Generally speaking, the wireless communication log is very many, at run time not necessary to record, but we can still through the command, set the record:

D:\UNSETUP\ANDROID-SDK-WINDOWS-1.0_R1\TOOLS>ADB Shell

# Logcat-b Radio

Logcat-b Radio

D/htc_ril (+): (t=1239390296) << 0

D/htc_ril (+): (t=1239390296) >> [email protected]=0

D/htc_ril (+): (t=1239390296) << 0

D/htc_ril (+): (t=1239390296) >> AT+CSQ

D/htc_ril (+): (t=1239390296) << +csq:29,99

D/htc_ril (30): 0

D/htc_ril (+): (t=1239390296) >> At+creg?

D/htc_ril (+): (t=1239390296) << +creg:2,3

D/htc_ril (30): 0


Get the ID and serial number of the device
ADB get-product

D:\UNSETUP\ANDROID-SDK-WINDOWS-1.0_R1\TOOLS>ADB Get-serialno

ht843gz03305

11. Via Remote shell-side run AQLite3 Connection Database

Through the ADB remote shell side, the database can be managed via Android's soft aqlite 3 command program. The SQLite 3 tool contains many use commands, such as. Dump to display the contents of the table, the. Schema can display the SQL create result set for the table space that already exists. SQLite3 also allows SQL commands to be executed remotely.

With SQLite 3, follow the previous method to log in to the remote shell side of the emulator, and then launch the tool to use the SQLite 3 command. When SQLite 3 is started, you can also specify the full path of the database you want to view. The emulator/Device instance saves the SQLite3 database in the folder/data/data/<package_name>/databases/.

Examples are as follows:

$ adb shell

# sqlite3/data/data/com.example.google.rss.rssexample/databases/rssitems.db

SQLite version 3.3.12

Enter '. Help ' for instructions

.... Enter commands, then quit ...

Sqlite>. Exit

When you start SQLite 3, you can send SQLite 3 through the shell side, command. Exit the ADB remote shell with the exit or <Ctrl+D> key combination.

12.ADB Command List

The following table lists all the commands supported by ADB and describes their meanings and how they are used.

Category

Command

Description

Comments

Options

-D

Manage ABD only via USB interface

Return error if not only managed with USB interface

-E

Manage adb only through simulator instances

Returns an error if it is not managed only by the emulator instance

-S <serialNumber>

Manage adb by sending commands via the simulator/device's allow command number (e.g. "Emulator-5556″")

If no number is specified, an error is given

General

Devices

View a list of all the facilities that connect the simulator/device

Find out more about querying for Emulator/device Instances

Help

View all the commands supported by ADB

Version

View ADB's version serial number

Debug

Logcat [<option>] [<filter-specs>]

Output log data to the screen

Bugreport

View bug reports such as Dumpsys, Dumpstate, and logcat information

Jdwp

View available JDWP information for a specified facility

You can use the forward jdwp:<pid> port mapping information to connect to the specified JDWP process, for example:
ADB forward tcp:8000 jdwp:472
Jdb-attach localhost:8000

Data

Install <path-to-apk>

Install Android for (can simulator/facility data file. APK specifies the full path)

Pull <remote> <local>

Copy the specified file from the emulator/facility to the computer

Push <local> <remote>

Copy the specified file from the computer to the emulator/device

Ports and Networking

Forward <local> <remote>

Remote connection Simulator/facility using the socket method with a locally specified port

The port needs to describe the following information:

  • Tcp:<portnum>
  • Local:<unix Domain Socket name>
  • Dev:<character Device name>
  • Jdwp:<pid>

PPP <tty> [Parm] ...

To run PPP via USB:

  • <tty>-the TTY for PPP stream. For Exampledev:/dev/omap_csmi_ttyl.
  • [Parm] ... &mdash zero or more PPP/PPPD options, such as Defaultroute, local, Notty, etc.

You need to be reminded that PDP connections cannot be started automatically

Scripting

Get-serialno

To view the serial number of an ADB instance

View querying for Emulator/device Instances to get more information

Get-state

View the current status of the simulator/facility

Wait-for-device

If the device is not online, it is not allowed to execute, that is, when the instance state is device

The command can be reproduced in advance in the ADB command, commands in the command will not execute other commands before the simulator/device connection, the example is as follows:

ADB wait-for-device Shell Getprop

It is necessary to note that these commands do not start the ADB until all the systems start up, so no other commands can be executed until all the systems start up, for example, when the install is used, the Android package needs to be fully booted, for example:

ADB wait-for-device Install <app>.apk

The above command is only connected to the emulator/device connection on which the ADB service will be executed, and an error will occur before the Android system is fully booted.

Server

Start-server

Select whether the service starts the ADB service process

Kill-server

Terminate ADB service process

Shell

Shell

Controlling emulator/Device instances with remote shell commands

See more information For more information

Shell [<shellcommand>]

Connection Simulator/Facility Execute shell command, exit remote shell end after execution

Use of the Android ADB tool

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.