开发常用命令合集 ADB 篇

Android 调试桥 (adb) 是一种功能多样的命令行工具,可让您与设备进行通信。adb 命令可用于执行各种设备操作,例如安装和调试应用。adb 提供对 Unix shell(可用来在设备上运行各种命令)的访问权限。

  • 基本用法
# 查看连接设备
adb devices

# 开启root权限
adb root

# 设置文件系统/system部分置于可写入的模式(适用于已被root的设备)
adb remount

# 从本地复制文件到设备
adb push <local> <devices>

# 从设备复制文件到本地
adb pull <devices> <local>

# 重启设备
adb reboot

# 设备关机
adb reboot -p

# 进入boot
adb reboot bootloader

# 打开shell命令
adb shell
  • 截图录屏
# 截图
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png /home/user/

# 录制
adb shell screenrecord /sdcard/screenrecord.mp4
adb pull /sdcard/screenrecord.mp4 /home/user/
  • 抓取日志log
# 抓取所有log
adb logcat -b all
adb logcat -b all | grep -i AndroidRuntime
# 抓取crash
adb logcat -b crash
# 抓取log为e部分
adb logcat -s *:e
# 同时过滤key0和key1二个关键词
adb logcat -b all | grep -E "key0|key1"
  • 屏幕相关
# 屏幕分辨率
adb shell wm size
adb shell wm size 720x1600
adb shell wm size reset

# 屏幕密度
adb shell wm density
adb shell wm density 320
adb shell wm density reset
  • 属性相关
# 读取
adb shell getprop <属性名>
adb shell getprop ro.debuggable
# 查看设备信息
adb shell getprop | grep product
# 设置
adb shell setprop ro.debuggable 1
# 查看selinux权限
adb shell getenforce
# 关闭Selinuxu权限
adb shell setenforce 0
  • adb dumpsys
# 查看activity
adb shell dumpsys activity | grep Resume
# 列出所有的安装应用的信息
adb shell dumpsys package
# 查看某个包的具体信息
adb shell dumpsys package com.android.XXX
  • adb 模拟电量
# 查看手机电量信息
adb shell dumpsys battery
# 模拟手机充电状态
adb shell dumpsys battery set status 2
# 模拟手机为非充电状态
adb shell dumpsys battery set status 1
# 模拟手机断开充电
adb shell dumpsys battery unplug
# 模拟手机电量
adb shell dumpsys battery set level X (X 代表电量)
# 复位,恢复实际状态
adb shell dumpsys battery reset
  • adb 服务
# 关闭adb服务  
adb kill-server
# 开启adb服务  
adb start-server
  • adb settings
# 查看所有设置
adb shell settings list system
adb shell settings list global
adb shell settings list secure

# get方法
adb shell settings get global bluetooth_on
# set方法
adb shell settings put global bluetooth_on 1
  • adb pm
# 列出所有的包名
adb shell pm list packages
# 查看安装路径
adb shell pm path com.android.XXX
# 清理数据缓存
adb shell pm clear com.android.settings.intelligence
# 查看版本号
adb shell pm dump com.android.XXX | grep -i version
  • adb am
# 启动应用界面
adb shell am start -n 包名/包名+类名
adb shell am start -n com.example.mytest/com.example.mytest.MainActivity
  • adb input
# 模拟按下数字0键(按键码参考:frameworks/base/core/java/android/view/KeyEvent.java)
adb shell input keyevent "KEYCODE_0"
# 模拟按下返回键
adb shell input keyevent 4
# 输出文本
adb shell input text bcoder.com
# 模拟点击
adb shell input touchscreen tap 110 66
# 模拟滑动(x1,y1)-(x2,y2)
adb shell input touchscreen swipe 450 66 110 66
  • 安装与卸载App
adb install test.apk
# 覆盖安装
adb install -r test.apk
# 安装测试apk
adb install -t test.apk
# 卸载应用
adb shell uninstall <包名>
adb shell uninstall com.android.XXX
  • 刷入单编模块
adb root 
adb remount
adb push \LA.UM.5.6\out\target\product\msm8937_32\system\priv-app\SystemUI /system/priv-app/
adb reboot
  • 刷入系统
adb reboot bootloader
fastboot flash boot boot.img
fastboot reboot
  • 刷机命令
# 重新启动到recovery
adb reboot recovery
# 重新启动到bootloader,即进入fastboot
adb reboot bootloader 
# 线刷ROM包
adb sideload D:/MIUI12-20200723.zip
  • fastboot命令
fastboot devices
fastboot reboot
fastboot reboot-bootloader
fastboot flash recovery recovery.img
fastboot flash boot boot.img
fastboot devices -l 列举设备
fastboot flashing lock 15年以后
fastboot oem lock 15年以前
fastboot flash recovery twrp-3.0.2-0-hammerhead.img 刷入recovery
fastboot reboot 重启手机
fastboot oem get-bootinfo


adb wait-for-device #等待设备

adb reboot-bootloader #这个是重启到bootloader界面 默认是fastboot。

fastboot flash boot boot.img #这个是刷入boot的命令。官解的要手动刷一次。

fastboot flash recovery recovery.img #刷入recovery 已有recovery的可以跳过。

fastboot erase boot #擦除boot分区

fastboot erase system -w #擦除system分区、 userdata分区和cache分区

fastboot update update.zip #将update.zip刷入

fastboot reboot #重启手机
  • 其他
# 访问主机
adb shell ping
# 查看你网络连接
adb shell ifconfig
# 查看进程的静态快照片
adb shell ps
# 查看运行进程信息
adb shell top
# 查看时间
adb shell date
# 挂载信息
adb shell mount
# 查看文件
adb shell cat
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值