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

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 binary
filterspecs 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>:v

If 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_LOG
or 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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值