常用adb 和 adb shell 命令

版权声明:https://blog.csdn.net/weixin_40811410 https://blog.csdn.net/weixin_40811410/article/details/82015773

一、ADB命令(电脑上操作的命令)

ADB常用命令:

1. 查看设备: 查看当前连接的设备,
adb  devices
2. 安装软件:将指定的apk文件安装到设备上
adb  install <apk文件路径>
如: adb install com.sina.weibo   
  • 参数“-r”,它是更新安装的意思,
  • 参数 -s ,安装到sdcard.
3. 卸载软件
adb  uninstall <包名>
如: adb uninstall com.sina.weibo 

如果加 -k 参数,为卸载软件但是保留配置和缓存文件.

4. 登录设备shell
adb  shell 
adb shell <command命令>
如:  adb  shell cat /proc/kmsg 

登录设备的shell,后面加

5. 从电脑上发送文件到设备 :可以把本机电脑上的文件或者文件夹复制到设备(手机)
adb push <本地路径> <远程路径>
如: adb push /local/build.prop  /system/build.prop
6. 从设备上下载文件到电脑:可以把设备(手机)上的文件或者文件夹复制到本机电脑
adb  pull <远程路径> <本地路径>
如: adb  /system/build.prop  /local/
7. 同步更新
adb sync [ <directory> ]
如: adb sync /data/

如果不指定目录,将同时更新 /data 和 /system/

8. 显示帮助信息
adb  help
9. 重新挂载
adb  remount

重新挂载系统 分区 用于读写

10. 启动和关闭server
adb start-server             - ensure that there is a server running
adb kill-server              - kill the server if it is running
11. 重启设备
adb reboot [bootloader|recovery]      - reboots the device, optionally into the bootloader or recovery program
12. 查看Log
[adb] logcat [<option>] ... [<filter-spec>] ..
  • -b 加载一个可使用的日志缓冲区供查看,比如event 和radio . 默认值是main 。具体查看Viewing Alternative Log Buffers.
  • -c 清楚屏幕上的日志.
  • -d 输出日志到屏幕上.
  • -f 指定输出日志信息的 ,默认是stdout .
  • -g 输出指定的日志缓冲区,输出后退出.
  • -n 设置日志的最大数目 .,默认值是4,需要和 -r 选项一起使用。
  • -r 每 时输出日志,默认值为16,需要和-f 选项一起使用.
  • -s 设置默认的过滤级别为silent.
  • -v 设置日志输入格式,默认的是brief 格式
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
13、查看bug报告:
adb bugreport

二、adb shell命令(手机设备上操作的命令)

常用adb shell命令:

1. 按键事件
input text <string>   input a string to device
input keyevent <event_code>   send a Key Event to device
如: adb shell input keyevent 26      (PowerKey)
2. am命令
命令 作用 例子
am start [options] 启动Activity am start -n com.eg.android.AlipayGphone/com.alipay.mobile.payee.ui.PayeeQRSetMoneyActivity
am startservice 启动Service am startservice com.miui.powerkeeper
am stopservice 停止Service
am broadcast 发送广播
am kill kill指定进程
am force-stop 强制停止某进程
am hang 系统hang住
am restart 重启手机
am dumpheap 将进程pid的堆信息输出到file
am start [options] 的options参数
  • (1)am启动activity:
adb shell am start -n com.android.settings/com.android.settings.Settings
adb shell am start - com.android.settings/com.android.settings.Settings
  • (2)-a :am start -a -d
am start -a android.intent.action.DIAL -d tel:10010 //编辑电话(在拨号盘界面按下电话号码,但是不拨打)
am start -a android.intent.action.VIEW -d http://www.baidu.com  //打开某个网址
am start -a android.intent.action.MUSIC_PLAYER  //打开音乐播放器
  • (3)-d :启动时,要传入的URI
am start -d content://contacts/people/1
  • (4)-n :直接启动一个组件
adb shell am start -n com.android.settings/com.android.settings.Settings
  • (5)-t : 指定Intent MIME Type
am start -t image/png
  • (6)-c [-c ] …]:指定Intent category
am start -c android.intent.category.APP_CONTACTS
3. pm 命令
命令 作用
pm list packages 列举app包信息
pm install [options] 安装应用
pm uninstall [options] 卸载应用
pm hide 隐藏应用
pm unhide 显示应用
pm get-install-location 获取安装位置
pm clear 清空App数据
pm force-dex-opt dex优化
pm dump dump信息
pm install [options] 的options参数
  • -r: 覆盖安装已存在Apk,并保持原有数据;
  • -d: 运行安装低版本Apk;
  • -t: 运行安装测试Apk
  • -i
4. dumpsys命令
dumpsys activit
dumpsys activity intents
dumpsys activity broadcasts
dumpsys activity providers
dumpsys activity services
dumpsys activity activities
dumpsys activity processes
获取当前activity信息

adb shell dumpsys activity top 
dumpsys window
dumpsys window windows
dumpsys window tokens
dumpsys window sessions
dumpsys window policy
dumpsys window input
获取当前activity名称

如:adb shell dumpsys window windows | findstr Current 


YunSoul技术分享,扫码关注微信公众号

    ——只要你学会了之前所不会的东西,只要今天的你强过了昨天的你,那你就一直是在进阶的路上了。

猜你喜欢

转载自blog.csdn.net/weixin_40811410/article/details/82015773