adb 基本命令大全
-----------查看设备连接状态 系列-----------
adb get-serialno 获取设备的ID和序列号serialNumber
adb devices查询当前计算机上连接那些设备(包括模拟器和手机),输出格式: [serialNumber] [state]
adb get-state 查看模拟器/设施的当前状态.
说明:
序列号[serialNumber]——由adb创建的一个字符串,这个字符串通过自己的控制端口<type>-<consolePort>
唯一地识别一个模拟器/设备实例。一个序列号的例子:emulator-5554
-----------发送命令到设备 系列-----------
adb [-d|-e|-s <serialNumber>] <command>
-d发送命令给usb连接的设备
-e发送命令到模拟器设备
-s <serialNumber>发送命令到指定设备
如启动手机设备shell: adb -d shell
adb forward <local> <remote>发布端口,可以设置任意的端口号,
做为主机向模拟器或设备的请求端口。如:adb forward tcp:5555 tcp:8000
adb reboot重启手机
adb remount将system分区重新挂载为可读写分区
adb kill-server终止adb服务进程
adb start-server重启adb服务进程
adb root已root权限重启adb服务
adb wait-for-device在模拟器/设备连接之前把命令转载在adb的命令器中
adb jdwp查看指定的设施的可用的JDWP信息.
可以用forward jdwp:<pid>端口映射信息来连接指定的JDWP进程.例如:
adb forward tcp:8000 jdwp:472
jdb -attach localhost:8000
adb shell am命令可以启动应用程序
adb shell input text <string> 向设备输入文本(光标所在的文本框)
adb shell input keyevent <event_code>向设备发送按键事件
如:
在编辑短信时,往文本框输入文本:adb shell input text "hello"
向手机发送键值回Home:adb shell input keyevent 3
event_code参考view/KeyEvent.java中的 KEYCODE_*
public static final int KEYCODE_SOFT_LEFT = 1;
public static final int KEYCODE_SOFT_RIGHT = 2;
public static final int KEYCODE_HOME = 3;
public static final int KEYCODE_BACK = 4;
public static final int KEYCODE_CALL = 5;
public static final int KEYCODE_ENDCALL = 6;
-----------安装卸载 系列-----------
adb install [-l] [-r] <file> - push this package file to the device and install it
('-l' means forward-lock the app)
('-r' means reinstall the app, keeping its data)
adb uninstall [-k] <package> - remove this app package from the device
('-k' means keep the data and cache directories)
如:
adb install d:\hello.apk
adb unstall com.huawei.hello
说明:如果带-r选项重新安装apk时,安装在/data/local/tmp/目录下,手机重启后还是使用原来的apk.
-----------文件操作 系列-----------
adb push <local> <remote> - copy file/dir to device
adb pull <remote> <local> - copy file/dir from device
-----------基本linux shell命令 系列-----------
adb shell [command]
ls列出目录下的文件和文件夹
cd切换目录
rm删除目录和文件
cat 查看文件内容
ps可以看那个进程再跑
ps -x [PID]查看单个进程的状态
top可以看那个进程的占用率最高
su切换到root用户
kill [pid]杀死一个进程
chmod 777 <file>修改该文件为可执行权限
详细使用情况可以登录一台Linux服务器在shell下查看帮助手册, man <command>
-----------查看系统状态和信息 系列-----------
adb shell procrank查询各进程内存使用情况
adb shell service list查看services信息
adb shell cat /proc/meminfo查看当前的内存情况
adb shell cat /proc/cpuinfo查看CPU信息(硬件)
adb shell cat /proc/iomem 查看IO内存分区
adb shell getprop列出系统所有属性
adb shell getprop | findstr "gsm"列出包含gsm的属性
adb shell setprop <key> <value> 修改系统属性
adb shell sqlite3可以执行sql语句查看数据库信息, 具体使用情况待调查
-----------Log系列-----------
adb logcat [ <filter-spec> ] - View device log
1~~~~~~~~~~~查看可用日志缓冲区:
adb logcat -b radio —查看缓冲区的相关的信息.
adb logcat -b events —查看和事件相关的的缓冲区.
adb logcat -b main —查看主要的日志缓冲区
2~~~~~~~~~~~过滤日志输出:
过滤器语句按照下面的格式描tag:priority ... , tag表示是标签, priority是表示标签的报告的最低等级
adb logcat *:W 显示优先级为warning或更高的日志信息
adb logcat ActivityManager:I MyApp:D *:S
日志的标签是系统部件原始信息的一个简要的标志。(比如:“View”就是查看系统的标签).
优先级有下列集中,是按照从低到高顺利排列的:
V — Verbose (lowest priority)
D — Debug
I — Info
W — Warning
E — Error
F — Fatal
S — Silent (highest priority, on which nothing is ever printed)
如果你电脑上运行logcat,相比在远程adbshell端,你还可以为环境变量ANDROID_LOG_TAGS :输入一个参数来设置默认的过滤
export ANDROID_LOG_TAGS="ActivityManager:I MyApp:D *:S"
需要注意的是ANDROID_LOG_TAGS过滤器如果通过远程shell运行logcat或用adb shell logcat来运行模拟器/设备不能输出日志.
3~~~~~~~~~~~控制日志输出格式:
日志信息包括了许多元数据域包括标签和优先级。可以修改日志的输出格式,所以可以显示出特定的元数据域。可以通过-v选项得到格式化输出日志的相关信息.
brief — Display priority/tag and PID of originating process (the default format).
process — Display PID only.
tag — Display the priority/tag only.
thread — Display process:thread and priority/tag only.
raw — Display the raw log message, with no other metadata fields.
time — Display the date, invocation time, priority/tag, and PID of the originating process.
long — Display all metadata fields and separate messages with a blank lines.
当启动了logcat,你可以通过-v选项来指定输出格式:
[adb] logcat [-v <format>]
下面是用thread来产生的日志格式:
adb logcat -v thread
需要注意的是你只能-v选项来规定输出格式option.
4~~~~~~~~~~~Logcat命令列表
-b <buffer> 加载一个可使用的日志缓冲区供查看,比如event和radio .默认值是main。具体查看Viewing Alternative Log Buffers.
-c 清楚屏幕上的日志.
-d 输出日志到屏幕上.
-f <filename> 指定输出日志信息的<filename>,默认是stdout .
-g 输出指定的日志缓冲区,输出后退出.
-n <count> 设置日志的最大数目<count> .,默认值是4,需要和-r选项一起使用。
-r <kbytes> 每<kbytes>时输出日志,默认值为16,需要和-f选项一起使用.
-s 设置默认的过滤级别为silent.
-v <format> 设置日志输入格式,默认的是brief格式,要知道更多的支持的格式,参看Controlling Log Output Format
adb bugreport - return all information from the device
that should be included in a bug report.
adb shell dmesg 查询内核缓冲区信息
adb shell dumpstate各类信息,比如进程信息,内存信息,进程是否异常,kernnel的log等
adb shell dumpcrash
adb shell dumpsys 查询所有service的状态
-----------其他-----------
模拟器使用镜像sdcard
用SDK里的mksdcard工具来创建FAT32磁盘镜像并在模拟器启动时加载它。这样创建镜像:? mksdcard <size> <file>,
比如我要创建一个64M的SD卡模拟文件,文件路径是在D:\workspace\sdcard.img
mksdcard 64000000 D:\workspace\sdcard.img
Emulator –sdcard D:\workspace\sdcard.img
或者在eclipse的run菜单的open run dialog对话框中配置启动参数。
#top
Usage: top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ]
-m num Maximum number of processes to display.
-n num Updates to show before exiting.
-d num Seconds to wait between updates.
-s col Column to sort by (cpu,vss,rss,thr).
-t Show threads instead of processes.
-h Display this help screen.
********* simple selection ********* ********* selection by list *********
-A all processes -C by command name
-N negate selection -G by real group ID (supports names)
-a all w/ tty except session leaders -U by real user ID (supports names)
-d all except session leaders -g by session OR by effective group name
-e all processes -p by process ID
T all processes on this terminal -s processes in the sessions given
a all w/ tty, including other users -t by tty
g OBSOLETE -- DO NOT USE -u by effective user ID (supports names)
r only running processes U processes for specified users
x processes w/o controlling ttys t by tty
*********** output format ********** *********** long options ***********
-o,o user-defined -f full --Group --User --pid --cols --ppid
-j,j job control s signal --group --user --sid --rows --info
-O,O preloaded -o v virtual memory --cumulative --format --deselect
-l,l long u user-oriented --sort --tty --forest --version
-F extra full X registers --heading --no-heading --context
TAG:
标题搜索
日历
|
|||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
1 | 2 | 3 | 4 | ||||||
5 | 6 | 7 | 8 | 9 | 10 | 11 | |||
12 | 13 | 14 | 15 | 16 | 17 | 18 | |||
19 | 20 | 21 | 22 | 23 | 24 | 25 | |||
26 | 27 | 28 | 29 | 30 | 31 |
我的存档
数据统计
- 访问量: 14787
- 日志数: 14
- 建立时间: 2010-12-09
- 更新时间: 2012-10-31