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。


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,923评论 18 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,285评论 25 708
  • 开源硬件门槛高,受众群体小,价格高,但是在国外购买力强,资源稀缺; 一般来说,开源硬件公司的商业模式,主要有三种:...
    方弟阅读 2,743评论 0 4
  • 记忆里,梦境总是平淡无奇,但却有那么两次,其中的感情浓烈的让我心惊。 一次是梦见与爱而不得的人告别,我用力...
    午后瞌睡猫阅读 280评论 0 0
  • 让你的全世界路过里,陈末问茅十八,为一个女人改变一生值得吗?茅十八说值得。真的值得吗?可惜猪头终不会幸福。如果救赎...
    宇文启阅读 265评论 0 0