adb配置环境变量以及常用命令

来源:互联网 发布:电视的mac什么意思 编辑:程序博客网 时间:2024/06/06 23:50

  • adb配置环境变量以及常用命令
    • 配置环境变量
    • adb常用命令行
    • adb抓取log日志
      • adb过滤tag
      • 抓取日志到文本文档

adb配置环境变量以及常用命令

在进行调试的时候,有时候ide抽疯或者在某些设备上(比如我的垃圾魅族mx5)会出现丢日志的情况,打断点或者使用Toast发现已经执行了,但是偏偏没有日志的情况,心里一万只doge奔跑过,其实我们可以通过adb来查看。

adb即Android Debug Bridge,Android调试桥,通过它我们可以查看当前的连接设备,开启、断开连接,以及抓取logcat日志等等。

配置环境变量

为了方便以后使用,不用每次都进入相应的文件夹下,我们首先配置一下环境变量。配置好环境变量,当在当前文件夹路径找不到指定的文件时候,就会去系统变量中配置好的路径查找,因此配置好之后,就不用每次重复进入到adb的文件夹了。

adb的路径在sdk\platform-tools目录下,首先我们进入环境变量下,添加到系统变量中,起一个变量名字并设置adb所在的路径。

配置好之后,不要忘记添加到path中,注意与前面的环境变量要用;隔开,已经设置好名字以及路径的,可以通过%环境变量名%,比如%adb%来设置。

在cmd中输入adb,我们发现测试成功。

adb常用命令行

下面介绍安卓系统常用adb命令:

命令行 作用 adb devices 显示当前连接的设备 adb kill-server 关闭adb服务进程 adb start-server 开启adb服务进程 adb install [apk路径] 安装指定的apk文件 adb reboot 重启设备 adb logcat 抓取logcat日志

adb抓取log日志

adb logcat

Usage: logcat [options] [filterspecs]options include:  -s              Set default filter to silent.                  Like specifying filterspec '*:s'  -f <filename>   Log to file. Default to stdout  -r [<kbytes>]   Rotate log every kbytes. (16 if unspecified). Requires -f  -n <count>      Sets max number of rotated logs to <count>, default 4  -v <format>     Sets the log print format, where <format> is one of:                  brief process tag thread raw time threadtime long  -c              clear (flush) the entire log and exit  -d              dump the log and then exit (don't block)  -t <count>      print only the most recent <count> lines (implies -d)  -g              get the size of the log's ring buffer and exit  -b <buffer>     Request alternate ring buffer, 'main', 'system', 'radio'                  or 'events'. Multiple -b parameters are allowed and the                  results are interleaved. The default is -b main -b system.  -B              output the log in binaryfilterspecs are a series of  <tag>[:priority]where <tag> is a log component tag (or * for all) and priority is:  V    Verbose  D    Debug  I    Info  W    Warn  E    Error  F    Fatal  S    Silent (supress all output)'*' means '*:d' and <tag> by itself means <tag>:vIf not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.If no filterspec is found, filter defaults to '*:I'If not specified with -v, format is set from ANDROID_PRINTF_LOGor defaults to "brief"

adb过滤tag

adb logcat [tag]:[Filter Level]
- tag:需要过滤的TAG
- Filter Level :设置过滤TAG的级别

运行结果如下:

抓取日志到文本文档

adb logcat [position]>[log.txt]
例:adb logcat -v time>xxxx.txt

运行之后,我们打开刚才的文本文档,就可以看到相应的日志了,其中搭配notepad++,我们可以直接查找到所有需要找到的TAG。

1 0
原创粉丝点击