ADB操作详解

adb帮助文档

1|root@Hi3798MV300:/ # adb help
Android Debug Bridge version 1.0.31

 -a                            - directs adb to listen on all interfaces for a connection
 -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 <specific device>          - directs command to the device or emulator with the given
                                 serial number or qualifier. 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.
 -H                            - Name of adb server host (default: localhost)
 -P                            - Port of adb server (default: 5037)
 devices [-l]                  - list all connected devices
                                 ('-l' will also list device qualifiers)
 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 command 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 --list           - list all forward socket connections.
                                 the format is a list of lines with the following format:
                                    <serial> " " <local> " " <remote> "\n"
  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 forward --no-rebind <local> <remote>
                               - same as 'adb forward <local> <remote>' but fails
                                 if <local> is already forwarded
  adb forward --remove <local> - remove a specific forward socket connection
  adb forward --remove-all     - remove all forward socket connections
  adb jdwp                     - list PIDs of processes hosting a JDWP transport
  adb install [-l] [-r] [-s] [--algo <algorithm name> --key <hex-encoded key> --iv <hex-encoded iv>] <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)
                                 ('--algo', '--key', and '--iv' mean the file is encrypted already)
  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 backup [-f <file>] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|-nosystem] [<packages...>]
                               - write an archive of the device's data to <file>.
                                 If no -f option is supplied then the data is written
                                 to "backup.ab" in the current directory.
                                 (-apk|-noapk enable/disable backup of the .apks themselves
                                    in the archive; the default is noapk.)
                                 (-obb|-noobb enable/disable backup of any installed apk expansion
                                    (aka .obb) files associated with each application; the default
                                    is noobb.)
                                 (-shared|-noshared enable/disable backup of the device's
                                    shared storage / SD card contents; the default is noshared.)
                                 (-all means to back up all installed applications)
                                 (-system|-nosystem toggles whether -all automatically includes
                                    system applications; the default is to include system apps)
                                 (<packages...> is the list of applications to be backed up.  If
                                    the -all or -shared flags are passed, then the package
                                    list is optional.  Applications explicitly given on the
                                    command line will be included even if -nosystem would
                                    ordinarily cause them to be omitted.)

  adb restore <file>           - restore device contents from the <file> backup archive

  adb help                     - show this help message
  adb version                  - show version num

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 get-devpath              - prints: <device-path>
  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.
root@Hi3798MV300:/ #

a、将USB调试模式切换为网络调试模式

首先必须保证手机和电脑在同一个无线局域网内,可以查看ip地址前三个字段相同即表示在同一个局域网,第一次连接必须使用USB调试模式,用USB线连接电脑和手机。

运行

D:\ADB>adb devices
List of devices attached
B2NGAC6831709731        device
将显示设备的序列号,同时需要手机端对电脑进行授权,否则将显示:
D:\ADB>adb devices
List of devices attached
B2NGAC6831709731        unauthorized
切换至监听5555端口

D:\ADB>adb tcpip 5555
restarting in TCP mode port: 5555

D:\ADB>adb connect 10.1.6.155
connected to 10.1.6.155:5555

D:\ADB>adb devices
List of devices attached
10.1.6.155:5555 device

b、查看安装的程序包

D:\ADB>adb shell pm list packages
package:com.evenwell.gallery
package:com.evenwell.gallery.overlay.base.s600cn
package:com.github.shadowsocks
package:com.evenwell.DbgCfgTool.overlay.base.s600cn
package:com.qualcomm.qti.haven.telemetry.service
package:com.android.cts.priv.ctsshim
package:com.qualcomm.qti.auth.sampleextauthservice
package:com.evenwell.pandorasbox.app
package:com.evenwell.SetupWizard.overlay.base.s600cn
package:com.google.android.ext.services
package:com.android.providers.telephony
package:com.android.providers.calendar
package:com.android.providers.media
package:com.evenwell.phone.overlay.base.s600cn
package:com.qti.service.colorservice
package:org.getlantern.lantern
adb shell pm list packages
package:com.evenwell.gallery
package:com.evenwell.gallery.overlay.base.s600cn
package:com.github.shadowsocks
package:com.evenwell.DbgCfgTool.overlay.base.s600cn
package:com.qualcomm.qti.haven.telemetry.service
package:com.android.cts.priv.ctsshim
package:com.qualcomm.qti.auth.sampleextauthservice
package:com.evenwell.pandorasbox.app
package:com.evenwell.SetupWizard.overlay.base.s600cn
package:com.google.android.ext.services
package:com.android.providers.telephony
package:com.android.providers.calendar
package:com.android.providers.media
package:com.evenwell.phone.overlay.base.s600cn
package:com.qti.service.colorservice
package:org.getlantern.lantern

将列出所有安装的程序包,pm命令还有很多开关量进行控制:

adb shell pm list packages -f See their associated file.
adb shell pm list packages -d Filter to only show disabled packages.
adb shell pm list packages -e Filter to only show enabled packages.
adb shell pm list packages -s Filter to only show system packages.
adb shell pm list packages -3 Filter to only show third party packages.
adb shell pm list packages -i See the installer for the packages.
adb shell pm list packages -u Also include uninstalled packages.
adb shell pm list packages --user <USER_ID> The user space to query.

c、复制文件到手机或电脑

经查阅资料需要先执行adb remount将设备设置为可读写,但是需要root权限,手机没有roor就无法进行尝试操作。

d:\platform-tools>adb remount
Not running as root. Try "adb root" first.

d:\platform-tools>adb root

从手机复制文件到电脑

adb pull /sdcard/demo.mp4 e:\

从电脑复制文件到手机

adb push d:\test.apk /sdcard

d、通过install和uninstall实现安装和卸载程序

 
adb install [option] <path>
adb install test.apk
adb install -l test.apk forward lock application
adb install -r test.apk replace existing application
adb install -t test.apk allow test packages
adb install -s test.apk install application on sdcard
adb install -d test.apk allow version code downgrade
adb install -p test.apk partial application install
 
db uninstall [options] <PACKAGE>
adb uninstall com.test.app
adb uninstall -k com.test.app Keep the data and cache directories around after package removal.
adb install /sdcard/***.apk
adb uninstall ***.apk

e、不root情况下,变相卸载系统内置应用,但是软件更新后依然会重新显现出来

用以下命令查看安装包的名称:

D:\ADB>adb shell pm list packages

确定需要禁用程序的名称

D:\ADB>adb shell pm disable-user com.android.browser
Package com.android.browser new state: disabled-user

解除禁用程序

D:\ADB>adb shell pm enable com.android.browser
Package com.android.browser new state: enabled

f、手机备份与恢复

注意其中几个开关量的默认值是-noapk,-noobb,-noshared,-nokeyvalue,这几个如果要备份,需要制定开关量。其中-system为默认选项可不指定,-all将备份所有应用。

d:\ADB>adb shell bu help
 backup [-f FILE] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all]
        [-system|-nosystem] [-keyvalue|-nokeyvalue] [PACKAGE...]
     write an archive of the device's data to FILE [default=backup.adb]
     package list optional if -all/-shared are supplied
     -apk/-noapk: do/don't back up .apk files (default -noapk)
     -obb/-noobb: do/don't back up .obb files (default -noobb)
     -shared|-noshared: do/don't back up shared storage (default -noshared)
     -all: back up all installed applications
     -system|-nosystem: include system apps in -all (default -system)
     -keyvalue|-nokeyvalue: include apps that perform key/value backups.
         (default -nokeyvalue)
 restore FILE             restore device contents from FILE

g、系统升级

首先将update.zip拷贝纸手机内存卡根目录下,运行

adb sideload update.zip

h、重启手机

重启后进入多种

 reboot [bootloader|recovery|sideload|sideload-auto-reboot]
     reboot the device; defaults to booting system image but
     supports bootloader and recovery too. sideload reboots
     into recovery and automatically starts sideload mode,
     sideload-auto-reboot is the same but reboots after sideloading.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值