ADB 调试学习笔记

常用指令

软件管理

  1. adb获取包名以及当前运行的activity Windows: findstr Linux: grep
    $ adb shell dumpsys window | findstr mCurrentFocus
    
  2. 列出所有已安装软件
    $ adb shell pm list packages
    
  3. 卸载软件
    $ adb shell pm uninstall [package_name]
    
  4. 安装软件
    $ adb shell pm install [package_name]
    
  5. 启动软件
    $ adb shell am start -W [package_name]/[activity_name]
    

文件管理

  1. 上传文件
    $ adb shell push [filename]
    
  2. 下载文件
    $ adb shell pull [filename]
    
  3. 删除文件
    $ adb shell rm [filename]
    

UI 获取

  1. 生成界面 xml
    $ adb shell uiautomator dump
    
  2. 屏幕截图
    $ adb shell screencap -p /sdcard/[filename].png
    

模拟操作

  1. 滑动
    $ adb shell input swipe [srcX] [srcY] [destX] [destY]
    
  2. 点击
    $ adb shell input tap [X] [Y]
    
  3. 输入文字(不支持中文)
    $ adb shell input text [text_content]
    

浏览器操作

  1. Chrome 同步
    # 连接之后在 Windows 桌面端的 Chrome 访问
    chrome://inspect/#devices
    
  2. 打开链接(使用系统默认浏览器)
    adb shell am start -a android.intent.action.VIEW -d http://www.cubat.cc
    
  3. 使用指定浏览器打开页面(以 Chrome 为例)
    adb shell am start -n com.android.chrome/com.google.android.apps.chrome.Main -a android.intent.action.VIEW -d "www.cubat.cc"
    
    adb shell am start -n com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity -d "about:newtab" --activity-clear-task
    

评论