美文网首页
Android adb常用命令

Android adb常用命令

作者: 胡萝卜有刺儿 | 来源:发表于2017-08-01 16:48 被阅读104次

    Android adb常用命令

    adb是什么

    Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components.
    i. A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as DDMS also create adb clients.
    ii. A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
    iii. A daemon, which runs as a background process on each emulator or device instance.
    看到篇文章可以熟悉一下 adb 源码分析
    adb的全称为Android Debug Bridge,就是起到调试桥的作用
    adb是android sdk里的一个工具, 用这个工具可以直接操作管理android模拟器或者真实的andriod设备.有三部分组件:
    i. 一个客户端,它运行在您的开发环境上。你可以通过一个终端来使用adb命令。如其他Android DDMS工具也是创建一个adb客户端。
    ii.一个服务器,它作为一个后台进程运行在您的开发环境上。服务器管理客户端和adb进程运行在模拟器/设备之间的通信。
    iii.一个进程,作为后台进程运行在模拟器/设备的实例。

    adb常用的一些命令

    adb命令用于自动化测试中,将为Android测试带来很大的便利。

    • 查看帮助
      adbadb help
    • 获取应用启动项
      adb shell monkey -p 包名 -c android.intent.category.LAUNCHER -v -v 0 | grep Using
    • 获取当前activity
      adb shell dumpsys activity activities | grep mFocusedActivity
      adb shell dumpsys window | grep mCurrent
    • 获取包安装路径
      adb shell pm path 包名
    • 开启-结束adb服务
      adb start-server adb kill-server
    • 获取设备列表信息
      adb devices
      操作多台设备时,adb -s <设备序列号> + <命令>
    • 重启手机
      adb reboot
    • 获取设备状态
      adb get-state devices:正常连接,offline:无响应,unknown:没有连接设备
    • 获取手机mac地址
      adb shell cat /sys/class/net/wlan0/address
    • 手机CPU序列号
      adb shell cat /proc/cpuinfo
    • 卸载apk
      adb uninstall <package name> 例: adb uninstall com.ex.example
    • 卸载apk,但保留数据
      adb uninstall -k <package name>
    • 安装apk
      adb install <apk file>
      例: adb install example.apk 保证apk路径无误。
    • 保留数据,重新安装apk
      adb install -r <apk file>
    • 系统日志
      adb logcat adb logcat > d:\logcat.log
    • bugreport
      adb bugreport adb bugreport > d:\bugreport.log
      打印dumpsys、dumpstate、logcat的输出,也是用于分析错误
    • 复制文件到本地
      adb pull sdcard/1.txt d:\
    • 推送文件到设备
      adb push d:\1.txt sdcard/
    • 无线连接设备
      usb连上设备后,
      查看设备的ip: adb shell ifconfig wlan0
      wlan0: ip 192.168.20.10 mask 255.255.254.0 flags [up broadcast running multicast]
      adb tcpip 5555
      log:restarting in TCP mode port: 5555
      adb connect 192.168.20.10:5555
      提示 connected to 192.168.20.64:5555 就可以拔掉usb了,
      切换回usb adb usb
    • adb shell 包含太多内容
      启动应用
      adb shell am start -n <package_name>/<activity_class_name> 例:adb shell am start -n com.ex.example/com.example.activity.WelcomActivityNew
      列出系统应用adb shell pm list package
      列出第三方应用 adb shell pm list package -s
      列出apk包的位置adb shell pm path com.ex.example
      adb shell ps adb shell top
    • adb 输入、滑动等操作
      输入域操作 adb shell input <string>
      物理键操作 adb shell input keyevent <key code number or name>
      keyevent指的是android对应的keycode,比如home键的keycode=3,back键的keycode=4
      点击操作 adb shell input tap <x> <y> (x,y)坐标
      滑动操作 adb shell input swipe <x1> <y1> <x2> <y2>
    • cpu值
      adb shell dumpsys cpuinfo
      adb shell dumpsys cpuinfo |grep packagename
      adb shell top -n 1| grep PackageName
    • 获取内存
      adb shell dumpsys meminfo
      adb shell dumpsys meminfo pakagename or Pid
    • 获取流量
      adb shell cat /proc/Pid/net/dev Pid为进程id
    • 截图
      adb shell /system/bin/screencap -p /sdcard/screen01.png
      adb pull /sdcard/screen01.png E:\11ss
    • 屏幕录制
      adb shell screenrecord /sdcard/record.mp4
      adb pulll /sdcard/record.mp4
    • 给app赋权限
      adb shell pm grant cn.com.weshare.jiekuan android.permission.INTERNET
    • 发送按键事件
      adb shell input keyevent KEYCODE_HOME 67 退格 3 home
    • 对屏幕发送一个触摸事件
      adb shell input tap 500 500
    • 滑动事件
      adb shell input swipe 300 300 300 900

    相关文章

      网友评论

          本文标题:Android adb常用命令

          本文链接:https://www.haomeiwen.com/subject/mccsxxtx.html