Android adb常用命令

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的全称为Android Debug Bridge,就是起到调试桥的作用
adb是android sdk里的一个工具, 用这个工具可以直接操作管理android模拟器或者真实的andriod设备.有三部分组件:
i. 一个客户端,它运行在您的开发环境上。你可以通过一个终端来使用adb命令。如其他Android DDMS工具也是创建一个adb客户端。
ii.一个服务器,它作为一个后台进程运行在您的开发环境上。服务器管理客户端和adb进程运行在模拟器/设备之间的通信。
iii.一个进程,作为后台进程运行在模拟器/设备的实例。

adb常用的一些命令

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

  • 查看帮助
    adbadb help
  • 开启-结束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

还有好多进阶命令·······,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值