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. webservice:com.sun.xml.internal.ws.server.ServerRtException: [failed to localize]

    发布webservice发生了错误,一直没有能够解决,错误如下: Exception in thread "main" com.sun.xml.internal.ws.server ...

  2. [JavaScript]为JS处理二进制数据提供可能性的WEB API

    写这篇博客的起源是在div.io上的一篇文章<你所不知道的JavaScript数组>by 小胡子哥下的评论中的讨论. 因为随着XHR2和现代浏览器的普及,在浏览器当中处理二进制不再向过去那 ...

  3. Oracle定时备份数据库

    1.导出命令:exp cpzxoa/cpzxoa@FENG file=D:\OracleBak\%date:~11,4%\jjmis_test.dmp log=D:\OracleBak\%date:~ ...

  4. Python traceback的优雅处理

    刚接触Python的时候,简单的异常处理已经可以帮助我们解决大多数问题,但是随着逐渐地深入,我们会发现有很多情况下简单的异常处理已经无法解决问题了,如下代码,单纯的打印异常所能提供的信息会非常有限. ...

  5. GDOI2018 涛涛摘苹果 [CDQ分治]

    传送门我会让你知道哪里有题面吗(逃 思路 显然不能模拟苹果下掉的过程,考虑计算每个苹果对询问的贡献. 显然一开始就有的苹果可以看做第0天变出来的,于是只需要考虑变出来的苹果了. 设当前询问节点\(x\ ...

  6. LONG数据类型转换为VARCHAR2并相互转换

    --方法1,支持表 --plsql中将long类型隐式转换为varchar2,但是sql不能CREATE OR REPLACE FUNCTION LONG_TO_CHAR( in_rowid rowi ...

  7. 开源中国社区 https://git.oschina.net/ 添加 SSH 公钥 添加

    首先可以参考官方的帮助文档 http://git.mydoc.io/?t=154712 然后进去码云首页 http://git.oschina.net 然后找到右边的头像点击一下  然后点击修改资料 ...

  8. Tomcat解决中文乱码并部署项目

    1.在Tomcat下的server.xml中添加URIEncoding="UTF-8"(解决中文乱码的问题) 2.在Tomcat下的server.xml中添加<Context ...

  9. vue之node.js的简单介绍

    一.什么是node.js? 它是可以运行JavaScript的服务平台,可以吧它当做一门后端程序,只是它的开发语言是JavaScript 二.安装 1.node.js的特性: - 非阻塞IO模型 - ...

  10. Python基础之类方法和静态方法

    小叙一会儿: 通常情况下,在类中定义的所有函数(注意了,这里说的就是所有,跟self啥的没关系,self也只是一个再普通不过 的参数而已)都是对象的绑定方法,对象在调用绑定方法时会自动将自己作为参数传 ...