Android ADB命令教程二——ADB命令详解

 
    我们使用 adb -h 来看看,adb命令里面包含了多少子命令:
 
C:\Windows\System32>adb -h
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 - directs command to the device or emulator with the given
                                 serial number or qualifier. Overrides ANDROID_SERIAL
                                 environment variable.
 -p - 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 [:] - connect to a device via TCP/IP
                                 Port 5555 is used by default if no port number is specified.
 disconnect [[:]] - 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 [-p]
                               - copy file/dir to device
                                 ('-p' to display the transfer progress)
  adb pull [-p] [-a] []
                               - copy file/dir from device
                                 ('-p' to display the transfer progress)
                                 ('-a' means copy timestamp and mode)
  adb sync [ ] - 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 - run remote shell command
  adb emu - run emulator console command
  adb logcat [ ] - View device log
  adb forward --list - list all forward socket connections.
                                 the format is a list of lines with the following format:
                                    " " " " "\n"
  adb forward - forward socket connections
                                 forward specs are one of:
                                   tcp:
                                   localabstract:
                                   localreserved:
                                   localfilesystem:
                                   dev:
                                   jdwp: (remote only)
  adb forward --no-rebind
                               - same as 'adb forward ' but fails
                                 if is already forwarded
  adb forward --remove - 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] [-d] [-s] [--algo --key --iv ]
                               - push this package file to the device and install it
                                 ('-l' means forward-lock the app)
                                 ('-r' means reinstall the app, keeping its data)
                                 ('-d' means allow version code downgrade)
                                 ('-s' means install on SD card instead of internal storage)
                                 ('--algo', '--key', and '--iv' mean the file is encrypted already)
  adb uninstall [-k] - 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 ] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|-nosystem] []
                               - write an archive of the device's data to .
                                 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) 
                                 ( 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 - restore device contents from the 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:
  adb get-devpath - prints:
  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 - restarts the adbd daemon listening on TCP on the specified port
networking:
  adb ppp [parameters] - Run PPP over USB.
 Note: you should not automatically start a PPP connection.
  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 [ ]
  can be interpreted in several ways:
 
  - If 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.
 
一、列出所有的可连接Android设备
 
C:\Windows\System32>adb devices
List of devices attached
emulator-5556 device
 
    第一列返回的就是设备的serialNumber,如果我们的机器上有多台android设备,可以使用该serialNumber去指定对应的唯一的Android设备去执行。
    使用adb get-serialno也可以获取得到serialNumber。
 
    执行结果是adb为每一个设备输出以下状态信息: 
 
    序列号(serialNumber) — 由adb创建的使用控制台端口号的用于唯一标识一个模拟器
或手机设备的字符串,格式是 <设备类型>-<端口号>,例如: emulator-5554
 
    状态(state) — 连接状态,其值是: 
offline — 未连接或未响应 
device —已经连接到服务商。注意这个状态并不表示Android系统已经完全启动起来,
 
    系统启动的过程中已经可以连接adb,但这个状态是正常的可操作状态。
 
二、操作指定的模拟器或手机 
 
    如果有多个模拟器或手机正在运行,当使用adb命令的时候就需要指定目标设备,这可以通过使用-s选项参数实现,用法是:
 
adb -s  
 
    即可以在adb命令中使用序列号指定特定的目标,前文已经提到的devices命令可以实现查询设备的序列号信息。 
 
    例如: 
 
adb -s emulator-5556 install helloWorld.apk 
 
    需要注意的是,如果使用了-s而没有指定设备的话,adb会报错。
 
三、安装应用程序 
 
    可以使用adb从开发用电脑中复制应用程序并且安装到模拟器或手机上,使用install命令即可,在这个命令中,必须指定待安装的.apk文件的路径: 
 
    adb install
 
    关于创建可安装的应用的更多信息,请参见Android Asset Packaging Tool (aapt). 注意,如果使用了安装有ADT插件的Eclipse开发环境,就不需要直接使用adb或aapt命令来安装应用程序了,ADT插件可以自动完成这些操作。
 
    对应的卸载命令是adb uninstall
 
四、转发端口 
 
    可以使用forward 命令转发端口 — 将特定端口上的请求转发到模拟器或手机的不同的端口上。下例是从6100端口转到7100端口:
 
    adb forward tcp:6100 tcp:7100 
 
    也可以使用UNIX命名的socket标识:
 
     adb forward tcp:6100 local:logd
 
五、与模拟器或手机传输文件 
 
    可以使用adb的 pull 和 push 命令从模拟器或手机中复制文件,或者将文件复制到模拟器或手机中。与 install 命令不同,它仅能复制.apk文件到特定的位置, pull 和 push 命令可以复制任意文件夹和文件到模拟器或手机的任何位置。 从模拟器或手机中复制一个文件或文件夹(递归的)使用: 
 
    adb pull  
 
    复制一个文件或文件夹(递归的)到模拟器或手机中使用: 
 
    adb push  
    
    在这个命令中和引用的是文件或文件夹的路径,在开发用电脑上的是local,在模拟器或手机上的是remote。 例如: 
 
    adb push foo.txt /sdcard/foo.txt
 
六、同步备份adb sync
 
    使用步骤:
    1、将Android设备上的/system或者/data目录拷贝到本地的一个路径,例如我本地是E:/Android
    2、如果Android设备上的/system或者/data目录修改了,想还原这两个文件夹,那么使用adb sync即可
 
    感觉这个命令没有多大用处,就是一个备份。
 
七、查看Android的运行日记信息
adb logcat

Android ADB命令教程二——ADB命令详解的更多相关文章

  1. Android数据存储(二)----PreferenceFragment详解

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  2. Android事件机制之二:onTouch详解

    <Android事件机制之一:事件传递和消费>一文总结了Android中的事件传递和消费机制. 在其中对OntachEvent中的总结中,不是很具体.本文将主要对onTach进行总结. o ...

  3. Android Studio系列教程五--Gradle命令详解与导入第三方包

    Android Studio系列教程五--Gradle命令详解与导入第三方包 2015 年 01 月 05 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://s ...

  4. Android Studio系列教程二--基本设置与运行

    Android Studio系列教程二--基本设置与运行 2014 年 11 月 28 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处! 上面一篇博客,介绍了Studio的 ...

  5. Android高手进阶教程(二十八)之---Android ViewPager控件的使用(基于ViewPager的横向相册)!!!

      分类: Android高手进阶 Android基础教程 2012-09-14 18:10 29759人阅读 评论(35) 收藏 举报 android相册layoutobjectclassloade ...

  6. Android 中各种权限深入体验及详解

    Android 中各种权限深入体验及详解 分类: Android2012-07-15 19:27 2822人阅读 评论(0) 收藏 举报 androidpermissionsinstallersyst ...

  7. android emulator启动的两种方法详解

    android emulator启动的两种方法详解    转https://blog.csdn.net/TTS_Kevin/article/details/7452237 对于android学习者,模 ...

  8. Spring Boot 启动(二) 配置详解

    Spring Boot 启动(二) 配置详解 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring Boot 配置 ...

  9. Nmap扫描教程之基础扫描详解

    Nmap扫描教程之基础扫描详解 Nmap扫描基础扫描 当用户对Nmap工具了解后,即可使用该工具实施扫描.通过上一章的介绍,用户可知Nmap工具可以分别对主机.端口.版本.操作系统等实施扫描.但是,在 ...

随机推荐

  1. 通过python生成nginx模板配置文件

    通过python生成nginx模板配置文件 # cat config.py #coding=utf-8 nginx_conf = ''' server {{ listen {port}; server ...

  2. 神经网络rbf

    clc; clear; close all; ld=400; %定义学习样本的数量 x=rand(2,ld); %得到一个2 * 400的一个矩阵,每个元素在0-1之间 x=(x-0.5)*1.5*2 ...

  3. Win7开机卡在Windows Update 35%的解决办法

    一台Win7老机器,多年未清理,用DISM++清理后,开机重启一直卡在Windows Update 35%转圈圈数小时,无法进入系统. 强制按关机键,F8进入安全模式依然同样现象. 查阅MSDN后,有 ...

  4. encoding and Endian

    Unicode, Code Point is the value of evry character in Unicode table(int,long,ll) Unicode defines a c ...

  5. python并发(阻塞、非阻塞、epoll)

    在Linux系统中 01 阻塞服务端 特征:1对1,阻塞. import socket server = socket.socket() #生成套接字对象 server.bind(('0.0.0.0' ...

  6. Day7--------------IP地址与子网划分

    1.ip地址:32位    172.16.45.10/16 网络位:前十六位是网络位 主机位:后16位是主机位 网络地址:172.16.0.0 主机地址:172.16.45.10 A类: 0NNNNN ...

  7. elasticsearch中的java.io.IOException: 远程主机强迫关闭了一个现有的连接

    [2018-07-31T14:29:41,289][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [9rTGh-y] caught exc ...

  8. Tp5自动验证

    <?php class DB { private $address = 'mysql.21future.com'; private $username = 'manbang'; private ...

  9. Confluence 6 内存使用和需求

    管理 Confluence 性能和内存的使用和有什么资源可用是密切相关的.如果你给 Confluence 更多的内存来缓存内容,Confluence 将会运行得更加迅速,但是相对比较低的内存环境中,C ...

  10. Confluence 6 数据库和临时目录

    数据库 所有的其他数据库,包括有页面,内容都存储在数据库中.如果你安装的 Confluence 是用于评估或者你选择使用的是 Embedded H2 Database 数据库.数据库有关的文件将会存储 ...