当前位置:首页 » PHP技术

【adb操作命令详解及大全】

2018-05-14 08:32 本站整理 浏览(5)

 

查看版本

$ adb version

Android Debug Bridge version 1.0.36
Revision 8f855a3d9b35-android

查看连接设备

输入以下命令可以查询已连接的设备与模拟器:

$ adb devices

List of devices attached
02ae0c1021089daf       device

安装一个apk,执行以下命令:

adb install <apkfile>

// 如: adb install demo.apk
如果不是当前目录,则后面要跟路径名:

adb install /Users/storm/temp/demo.apk
保留数据和缓存文件,重新安装apk:

adb install -r demo.apk
安装apk到sd卡:

adb install -s demo.apk
卸载

直接卸载:

adb uninstall <package>

// 如:adb uninstall com.stormzhang.demo
卸载 app 但保留数据和缓存文件:

adb uninstall -k com.stormzhang.demo

启动/停止 Server

一般来说,下面两个命令基本不会用到,因为只要设备连接正确,会自动启动 adb server 的,不过大家也需要知道这俩命令:

启动 adb server :

adb start-server

停止 adb server :

adb kill-server

列出手机装的所有app的包名:

adb shell pm list packages

列出系统应用的所有包名:

adb shell pm list packages -s

列出除了系统应用的第三方应用包名:

adb shell pm list packages -3

使用 grep 来过滤:

adb shell pm list packages | grep qq

清除应用数据与缓存

有些时候我们测试需要清除数据与缓存,则需要用到如下命令:

adb shell pm clear <packagename>

// 如:adb shell pm clear com.stormzhang.demo

启动应用

如果我们想要通过 adb 来启动应用
adb shell am start -n com.stormzhang.demo/.ui.SplashActivity

强制停止应用

有些时候应用卡死了,需要强制停止,则执行以下命令:

adb shell am force-stop <packagename>

// 如:adb shell am force-stop cn.androidstar.demo

查看日志

adb logcat

重启

adb reboot

获取序列号

$adb get-serialno

02ae0c1021089daf

获取 MAC 地址

$adb shell  cat /sys/class/net/wlan0/address

bc:f5:ac:f9:f7:c8

查看设备型号

$adb shell getprop ro.product.model

Nexus 5

查看 Android 系统版本

$adb shell getprop ro.build.version.release

7.0.1

查看屏幕分辨率

$adb shell wm size

Physical size: 1080×1920

查看屏幕密度

$adb shell wm density


 

 

 

 

参考命令:

Microsoft Windows XP [版本 5.1.2600]

(C) 版权所有 1985-2001 Microsoft Corp.

 

C:\Documents and Settings\Administrator>cd C:\share_soft\adb

 

C:\share_soft\adb>adb.exe

Android Debug Bridge version 1.0.26

 

 -d                            - directs command to the only connected USB device

                                 returns an error if more than one USB device is present.

 -e                            - directs command to the only running emulator.

                                 returns an error if more than one emulator is running.

 -s <serial number>            - directs command to the USB device or emulator with

                                 the given serial number. Overrides ANDROID_SERIAL

                                 environment variable.

 -p <product name or path>     - simple product name like 'sooner', or

                                 a relative/absolute path to a product

                                 out directory like 'out/target/product/sooner'.

                                 If -p is not specified, the ANDROID_PRODUCT_OUT

                                 environment variable is used, which must

                                 be an absolute path.

 devices                       - list all connected devices

 connect <host>[:<port>]       - connect to a device via TCP/IP

                                 Port 5555 is used by default if no port number is specified.

 disconnect [<host>[:<port>]]  - disconnect from a TCP/IP device.

                                 Port 5555 is used by default if no port number is specified.

                                 Using this ocmmand with no additional arguments

                                 will disconnect from all connected TCP/IP devices.

 

device commands:

  adb push <local> <remote>    - copy file/dir to device

  adb pull <remote> [<local>]  - copy file/dir from device

  adb sync [ <directory> ]     - copy host->device only if changed

                                 (-l means list but don't copy)

                                 (see 'adb help all')

  adb shell                    - run remote shell interactively

  adb shell <command>          - run remote shell command

  adb emu <command>            - run emulator console command

  adb logcat [ <filter-spec> ] - View device log

  adb forward <local> <remote> - forward socket connections

                                 forward specs are one of:

                                   tcp:<port>

                                   localabstract:<unix domain socket name>

                                   localreserved:<unix domain socket name>

                                   localfilesystem:<unix domain socket name>

                                   dev:<character device name>

                                   jdwp:<process pid> (remote only)

  adb jdwp                     - list PIDs of processes hosting a JDWP transport

  adb install [-l] [-r] [-s] <file> - push this package file to the device and install it

                                 ('-l' means forward-lock the app)

                                 ('-r' means reinstall the app, keeping its data)

                                 ('-s' means install on SD card instead of internal storage)

  adb uninstall [-k] <package> - remove this app package from the device

                                 ('-k' means keep the data and cache directories)

  adb bugreport                - return all information from the device

                                 that should be included in a bug report.

 

  adb help                     - show this help message

  adb version                  - show version num

 

DATAOPTS:

 (no option)                   - don't touch the data partition

  -w                           - wipe the data partition

  -d                           - flash the data partition

 

scripting:

  adb wait-for-device          - block until device is online

  adb start-server             - ensure that there is a server running

  adb kill-server              - kill the server if it is running

  adb get-state                - prints: offline | bootloader | device

  adb get-serialno             - prints: <serial-number>

  adb status-window            - continuously print device status for a specified device

  adb remount                  - remounts the /system partition on the device read-write

  adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program

  adb reboot-bootloader        - reboots the device into the bootloader

  adb root                     - restarts the adbd daemon with root permissions

  adb usb                      - restarts the adbd daemon listening on USB

  adb tcpip <port>             - restarts the adbd daemon listening on TCP on the specified port

networking:

  adb ppp <tty> [parameters]   - Run PPP over USB.

 Note: you should not automatically start a PPP connection.

 <tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1

 [parameters] - Eg. defaultroute debug dump local notty usepeerdns

 

adb sync notes: adb sync [ <directory> ]

  <localdir> can be interpreted in several ways:

 

  - If <directory> is not specified, both /system and /data partitions will be updated.

 

  - If it is "system" or "data", only the corresponding partition

    is updated.

 

environmental variables:

  ADB_TRACE                    - Print debug information. A comma separated list of the following values

                                 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp

  ANDROID_SERIAL               - The serial number to connect to. -s takes priority over this if given.

  ANDROID_LOG_TAGS             - When used with the logcat option, only these debug tags are printed.

 

C:\share_soft\adb>