"Xamarin Poach series: Android's most important command tool ADB"

Source: Internet
Author: User
Tags linux shell commands tmp folder unix domain socket

The ADB tool provides a good command-based control of the system.

As previously mentioned, the essence of Android is the virtual machine system running on Linux. In Linux, the operation of the system is done in the form of a command. In Linux, the Linux author writes the Linux kernel. In Linux for each manufacturer, a variety of shell management tools are available for Linux kernel-based management.

Linux Systems offer a variety of different shells to choose from. commonly used are Bourne shell (SH), c-shelll (abbreviated CSH), Korn Shell (Ksh), and Bourne Again Shell (bash).

Where SH bash is a more commonly used shell management tool. Contains more sophisticated command operations.

The ADB tool provides shell management Linux systems in Windwos Mac under different platforms. Once again remember, Android is the virtual machine of Linux!!!!!!!

With shell commands, you can manage your Android system.

such as: adb? --------can help view this command

(Reproduced below)

Http://mobile.163.com/09/1105/06/5NBAG1OQ00112K88.html

Http://www.cnblogs.com/devinzhang/archive/2011/12/17/2291411.html

Http://www.cnblogs.com/devinzhang/archive/2011/12/17/2291396.html

The Android simulator ADB command describes the important commands that are included in the Android emulator operation under the Tools folder of the SDK Adb,adb is all called Android Debug Bridge, which is the role of debug bridges
  • 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 debug bridges. With ADB we can debug the Android program via DDMS in Eclipse, which is the Debug tool.

    ADB's way of working is a special use to listen to 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 run automatically.

    1. The ADB can easily execute Linux shell commands, such as the adb Shell dir is the listing directory, the root directory in Linux/instead of Windows C, D disk.

    2. Install the APK program to the emulator to execute the ADB install android123.apk, so that the installation package named Android123 will be installed in the Android emulator, provided that the android123.apk file needs to be placed in the Sdk\ Tools directory.

    3. Transfer files to emulator, use the ADB push android123.txt/tmp/android123.txt command to transfer the Android123.txt file under Sdk\tools to the/tmp/folder of the simulator, It is important to note that the contents of the/tmp/folder are emptied when the Android emulator restarts. In addition to explaining the use of DDMS in the ADT plug-in,

    4. Returning files from the Android emulator to your computer

    Through the ADB pull/tmp/android123.txt android123.txt command will be the emulator's TMP folder under the Android123.txt file back to the computer Sdk\tools directory.

    Android adb command In addition to the easy installation of apk files, PC and Android simulator for data transfer, there are some auxiliary features of Android Debug Bridge.

    1. If there are * Daemon not running found in eclipse. Starting it now * tips to end adb

    ADB kill-server

    2. Show Android Emulator status

    ADB devices port number and other information, after execution will display TCP port number ADB get-product acquisition device model ADB Get-serialno get serial number

    3. Wait for the device that is running

    ADB wait-for-device

    4. Port forwarding

    ADB forward adb forward tcp:5555 tcp:1234 for forwarding the default TCP 5555 port to port 1234

    5. View Bug reports

    ADB bugreport

Use of the Android ADB tool

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) manage the predetermined port on the device or phone simulator;

(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 application to simulator 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. The Shell adb shell that enters the device or simulator can enter the shell environment of the device or emulator through the command above, and in this Linux shell, you can execute various Linux commands, In addition, if you want to execute only one shell command, you can do this in the following way: 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 to get a list of the currently running emulator/device instances 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 in general, there is a lot of traffic in the wireless communication, it is not necessary to record at runtime, but we can still set the record by command:

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

"Xamarin Poach series: Android's most important command tool 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.