WHS GIS Engineer

adb常用命令及常见问题

2017-04-11
WHS

常用的adb命令以及一些常见问题解决方法。

前提

要想在Mac或Windows上直接使用adb命令,需要配置环境变量,以Mac为例,配置方法如下:

  • 打开终端输入 touch .bash_profile 更新配置文件,如果不存在自动创建
  • open -e .bash_profile 打开配置文件
  • 输入如下内容并保存
    export PATH=${PATH}:/Users/{yourname}/Library/Android/sdk/platform-tools
    export PATH=${PATH}:/Users/{yourname}/Library/Android/sdk/tools
    

常用命令

# 查看adb 端口是否有占用   
adb nodaemon server   
# 查看adb端口占用进程 
lsof -i:5037 
# 查看package_name程序进程  
adb shell ps|grep com.ecarx.magicbook   
# 重置本地签名文件
rm -rf ~/.android 
# 结束所有adb相关进程
killall adb 
# 以root权限重启设备上的adbd服务
adb root
# 测量应用的启动时间
adb shell am start -W com.titan.asfh/com.titan.asfh.login.LoginActivity 
# /将sd卡中的文件拉到指定目录
adb pull sdcard1/PcmRecord D:/whs
# 查看已安装应用列表
adb shell pm list package
# 清除应用数据
adb shell pm clear com.iflytek.android.device
# adb 发送intent
adb shell am start -W -a android.intent.action.VIEW -d "shinevi://wx" com.wt.shanweicloud.ui.main
adb shell am start  -d "shinevi://xj"
# 发送广播
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.aichip.logservice/com.aichip.logservice.BootReceiver
# 查看 Android手机CPU类型 ARM、ARMV7、NEON
adb shell cd/proc cat cpuinfo
# 查看手机屏幕大小
adb shell wm size
adb 将当前页面的数据导出来
adb shell "uiautomator dump --compressed && cat /sdcard/window_dump.xml"
# 卸载系统应用
adb shell pm uninstall [-k] [--user USER_ID] 包名
# 例如卸载360浏览器
adb shell pm uninstall -k --user 0 com.qihoo.browser
# 查看应用报名
adb shell dumpsys window | grep mCurrentFocus
# 查看Android系统版本
adb shell getprop ro.build.version.sdk
# 查看进程信息
adb shell ps -A
# 查看某个进程的线程信息
adb shell ps -T -A | grep PID
# 导出logical 内容到文件
adb logcat -d > logcat.txt
# 切换白天黑夜模式
adb shell cmd uimode night yes
adb shell cmd uimode night no
# 退出
adb shell exit
关闭应用
adb shell am force-stop com.ecarx.magicbook。  //强制关闭
adb shell am kill com.ecarx.magicbook。        //安全关闭
# 查看应用版本信息
 adb shell dumpsys package com.ecarx.ai.val | grep version
adb shell dumpsys package com.ecarx.xiaokagui | grep version
# 查看车控进程
 adb shell ps|grep com.ecarx.xiaoka.carcontrol
# 查看顶层的activity
adb shell dumpsys activity top | grep ACTIVITY
# 启动服务/打开屏保
adb shell am startservice  -a android.intent.action.SCREENSAVER -n com.ecarx.screensaver/com.ecarx.screensaver.ScreensaverService    
# 修改为指定分辨率
adb shell wm size 1920x1080
# 恢复为默认分辨率
adb shell wm size reset
# 指定包名获取权限
adb shell pm grant com.ecarx.xiaokagui android.permission.WRITE_SECURE_SETTINGS
# 查看已安装包名
pm -l 
# Logcat 相关
# 清空
adb logcat -c
# 查看设备上缓冲区的大小
adb logcat -g
# 设置logcat 缓冲区大小
adb logcat -G 4M

常用脚本

adb 多次切换黑夜/白天模式脚本 
#!/bin/bash
adb shell cmd uimode night no
for b in {1..50}
do
  adb shell cmd uimode night no
  sleep 0.2
  adb shell cmd uimode night yes
  sleep 0.2
done

可能出现的问题

adb端口占用

错误代码:

Could not open Selected VM debug port (8700). Make sure you do not have another instance of DDMS or of the eclipse plugin running. If it's being used by something else, choose a new port number in the preferences.

解决方法:

  • killall adb 然后 重启Android Studio
  • 如果上面方法无效,请检查是否重复设置Android环境变量
  • 还有可能是Chrome DevTools已连接设备 Chrome 打开 chrome://inspect/#devices checkout设备,然后kill-server and adb devices。
  • open sdk manager and installed all android sdk tools and done.
  • Mac防火墙设置原因
  • 查看AS debugger 端口是否被占用 lsof -i:63341

错误信息:

$ adb devices
List of devices attached
* daemon not running. starting it now at tcp:5037 *
* daemon started successfully *
** daemon still not running
error: cannot connect to daemon at tcp:5037: Operation timed out

解决方法:

  • Close Android Studio 然后使用终端kill 占用adb的进程,重启AS(如果还是不行请重新插拔设备)。

错误信息:

下午4:13	Can't bind to local 8617 for debugger

下午4:15	Can't bind to local 8617 for debugger

下午4:15	Can't bind to local 8617 for debugger

下午4:15	Can't bind to local 8606 for debugger

解决方法:

  • 在Debugger Configuration 设置Debuger Type 为 Java

错误信息

adb server version (31) doesn't match this client (40); killing...
could not read ok from ADB Server
* failed to start daemon
error: cannot connect to daemon 

解决方法 原因:这个是socket 的端口被占用了,我这里是因为360安全助手占用了这个端口,所以其他的就不能够用了。就要删除手机助手的进程,如图里面的360Mobile

参考链接

黑科技之卸载Android系统应用!


Similar Posts

Comments