Kong Jing

常用ADB命令

21 October 2016

Android 手机与电脑之间有一种联系,就是ADB(Android Debug Bridge)。这样的一种工具,我们可以通过ADB 命令来操纵手机,ADB工具在Android SDK 的platform-tools目录下,使用cd命令或者切换到该目录下,将platform-tools的路径添加到系统环境变量中,这样就可以使用ADB命令了。


在Mac环境下的配置方式如下:

touch .bash_profile
open -e .bash_profile

添加自己的路径到打开的.bash_profile中。

export PATH=${PATH}:/Users/****/Library/Android/sdk/platform-tools

关闭文档,然后输入

source .bash_profile

输入下面的命令查看ADB版本号

adb version

在Windows环境下配置方式如下:

在环境变量中添加Android的变量,将c:\program files\android\sdk\platform-tools作为变量值添加进去。然后编辑存在的Path,在变量值最末端添加%Android%。然后测试ADB命令。

关闭被占用的ADB任务进程

Windows下发生ADB错误

* daemon not running. starting it now *   
ADB server didn't ACK   
* failed to start daemon *

使用语句查找原因

adb nodaemon server

查找adb的端口”5037”

netstat -anolfindstr "5037"

找到端口进程

tasklist|findstr "8516"

列出pid号

tasklist

杀掉该进程

taskkill /f /pid 963

Mac 下输入

vi .android/adb_usb.ini

在「命令行模式(command mode)」下按一下字母「i」就可以进入「插入模式(Insert mode)」,这时候你就可以开始输入文字了。

删除设备上一行空格

在「命令行模式(command mode)」下,按一下「:」冒号键进入「Last line mode」,例如:

w filename (输入 「w filename」将文章以指定的文件名filename保存)

wq (输入「wq」,存盘并退出vi)

q! (输入q!, 不存盘强制退出vi)

查看视频节点
ls dev/video*
显示系统中全部Android平台
android list targets
安装Apk程序之Install
adb install -r /Users/K/Desktop/test.apk
安装系统程序(需要权限)
adb push /Users/K/Desktop/test.apk /system/app/
写入文件到手机
adb push /Users/K/Desktop/test.apk /system/temp/
获取手机中的文件
adb pull /system/temp/a.txt /Users/K/Desktop/
查看Log
adb shell
$ logcat | grep "abc"
删除应用
adb remount(重新挂载系统分区,使系统分区重新可写)
adb shell
cd system/app
rm *.apk
查看系统盘符
adb shell df
输入所有已经安装的应用
adb shell pm list packages -f
模拟按键输入
adb shell input keyevent6

82-menu 3-home 19-up 20-down

21-left 22-right 66-enter 4-back

模拟滑动输入
adb shell input touchscreen swipe 18 665 18 350
查看运行状态
adb shell dumpsys
$ dumpsys activity activity activities | grep "tencent"
启动一个activity
adb shell am start -n com.test/com.test.TestActivity
录制屏幕
adb shell screenrecord /sdcard/demo.mp4

模拟 app 在后台被杀死, 在终端运行

adb shell am kill

adb抽取apk

pm命令

借助adb shell pm命令,将安装的所有应用包名列出来:

$ adb shell

$ pm list packages

第二步,找到apk的位置

$ adb shell pm path com.tence01.mm  package:/data/app/com.tence01.mm-1.apk

第三步,pull出来

$ adb pull /data/app/com.tence01.mm-1.apk ~/apks2407 KB/s (25567735 bytes in 10.370s)   

默认放在根目录下

其他的命令

adb shell wm size

查看屏幕的物理大小

adb shell logcat 

查看log日志

adb shell logcat > c:\t.txt

导出log日志到本地

如果有多台设备连接

adb devices
adb -s ***** shell

屏幕截图

screencap -p /sdcard/Screenshots/test.png

查看APP的应用信息、版本信息

adb shell dumpsys package com.examle.xx

删除root设备中的系统应用

adb root
adb remount
adb shell
cd system
cd app
rm -rf com.****

铁甲钢拳

你比昨天进步了吗?

— Kong Jing