ADB常用命令合集.docx
- 文档编号:9451421
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:11
- 大小:21.30KB
ADB常用命令合集.docx
《ADB常用命令合集.docx》由会员分享,可在线阅读,更多相关《ADB常用命令合集.docx(11页珍藏版)》请在冰豆网上搜索。
ADB常用命令合集
ADB常用命令合集
ADB常用命令合集
ADB(AndroidDebugBridge)
说明:
下面一些命令需要有root权限才能执行成功
快速启动dos窗口执行adb:
1.adb.exe所在路径添加到系统环境变量Path中
2.配置快捷键启动dos
进入C:
\*****\system32目录下,找到cmd.exe.
右击菜单“发送到“-桌面快捷方式。
在桌面上右击"快捷方式到cmd.exe"-"属性"-"快捷方式"页-光标高亮"快捷键"-按下自定义快捷键(如:
Ctrl+Alt+Z)任何情况下,按下Ctrl+Alt+Z启动dos窗口就可以执行adb命令了
-----------查看设备连接状态系列-----------
adbget-serialno获取设备的ID和序列号serialNumber
adbdevices查询当前计算机上连接那些设备(包括模拟器和手机),输出格式:
[serialNumber][state]
adbget-state查看模拟器/设施的当前状态.
说明:
序列号[serialNumber]――由adb创建的一个字符串,这个字符串通过自己的控制端口type-consolePort
唯一地识别一个模拟器/设备实例。
一个序列号的例子:
emulator-5554
-----------发送命令到设备系列-----------
adb[-d|-e|-sserialNumber]command
-d发送命令给usb连接的设备
-e发送命令到模拟器设备
-sserialNumber发送命令到指定设备
如启动手机设备shell:
adb-dshell
adbforwardlocalremote发布端口,可以设置任意的端口号,
做为主机向模拟器或设备的请求端口。
如:
adbforwardtcp:
5555tcp:
8000
adbreboot重启手机-----常用
adbremount将system分区重新挂载为可读写分区-----常用
adbkill-server终止adb服务进程-----常用
adbstart-server重启adb服务进程
adbroot已root权限重启adb服务
adbwait-for-device在模拟器/设备连接之前把命令转载在adb的命令器中adbjdwp查看指定的设施的可用的JDWP信息.
可以用forwardjdwp:
pid端口映射信息来连接指定的JDWP进程.例如:
adbforwardtcp:
8000jdwp:
472
jdb-attachlocalhost:
8000
adbshellam命令可以启动应用程序
adbshellinputtextstring向设备输入文本(光标所在的文本框)adbshellinputkeyeventevent_code向设备发送按键事件
如:
在编辑短信时,往文本框输入文本:
adbshellinputtext“hello"向手机发送键值回Home:
adbshellinputkeyevent3
event_code参考view/KeyEvent.java中的*****_*
publicstaticfinalint*****_SOFT_LEFT=1;
publicstaticfinalint*****_SOFT_RIGHT=2;
publicstaticfinalint*****_HOME=3;
publicstaticfinalint*****_BACK=4;
publicstaticfinalint*****_CALL=5;
publicstaticfinalint*****_*****=6;
-----------安装卸载系列----------------常用
adbinstall[-l][-r]file-pushthispackagefiletothedeviceandinstallit
('-l'meansforward-locktheapp)
('-r'meansreinstalltheapp,keepingitsdata)
adbuninstall[-k]package-removethisapppackagefromthedevice('-k'meanskeepthedataandcachedirectories)
如:
adbinstalld:
\hello.apk
adbunstallcom.huawei.hello
说明:
如果带-r选项重新安装apk时,安装在/local/tmp/目录下,手机重启后还是使用原来的apk.
-----------文件操作系列----------------常用
adbpushlocalremote-copyfile/dirtodevice
adbpullremotelocal-copyfile/dirfromdevice
-----------基本linuxshell命令系列----------------常用
adbshell[command]
ls列出目录下的文件和文件夹
cd切换目录
rm删除目录和文件
cat查看文件内容
ps可以看那个进程再跑
ps-x[PID]查看单个进程的状态
top可以看那个进程的占用率最高
su切换到root用户
kill[pid]杀死一个进程
chmod777file修改该文件为可执行权限
详细使用情况可以登录一台Linux服务器在shell下查看帮助手册,mancommand
-----------查看系统状态和信息系列-----------(较常用)
adbshellprocrank查询各进程内存使用情况
adbshellservicelist查看services信息
adbshellcat/proc/meminfo查看当前的内存情况
adbshellcat/proc/cpuinfo查看CPU信息(硬件)
adbshellcat/proc/iomem查看IO内存分区
adbshellgetprop列出系统所有属性
adbshellgetprop|findstr“gsm"列出包含gsm的属性
adbshellsetpropkeyvalue修改系统属性
adbshellsqlite3可以执行sql语句查看数据库信息,具体使用情况待调查
-----------Log系列-----------
adblogcat[filter-spec]-Viewdevicelog
1~~~~~~~~~~~查看可用日志缓冲区:
adblogcat-bradio―查看缓冲区的相关的信息.
adblogcat-bevents―查看和事件相关的的缓冲区.
adblogcat-bmain―查看主要的日志缓冲区
2~~~~~~~~~~~过滤日志输出:
过滤器语句按照下面的格式描tag:
priority...,tag表示是标签,priority是表示标签的报告的最低等级
adblogcat*:
W显示优先级为warning或更高的日志信息
adblogcatActivityManager:
IMyApp:
D*:
S
日志的标签是系统部件原始信息的一个简要的标志。
(比如:
“View”就是查看系统的标签).
优先级有下列集中,是按照从低到高顺利排列的:
V―Verbose(lowestpriority)
D―Debug
I―Info
W―Warning
E―Error
F―Fatal
S―Silent(highestpriority,onwhichnothingiseverprinted)
如果你电脑上运行logcat,相比在远程adbshell端,你还可以为环境变量*****_LOG_TAGS:
输入一个参数来设置默认的过滤
export*****_LOG_TAGS=“ActivityManager:
IMyApp:
D*:
S"
需要注意的是*****_LOG_TAGS过滤器如果通过远程shell运行logcat或用adbshelllogcat来运行模拟器/设备不能输出日志.
3~~~~~~~~~~~控制日志输出格式:
日志信息包括了许多元数据域包括标签和优先级。
可以修改日志的输出格式,所以可以显示出特定的元数据域。
可以通过-v选项得到格式化输出日志的相关信息.
brief―Displaypriority/tagandPIDoforiginatingprocess(thedefaultformat).
process―DisplayPIDonly.
tag―Displaythepriority/tagonly.
thread―Displayprocess:
threadandpriority/tagonly.
raw―Displaytherawlogmessage,withnoothermetadatafields.time―Displaythedate,invocationtime,priority/tag,andPIDoftheoriginatingprocess.
long―Displayallmetadatafieldsandseparatemessageswithablanklines.
当启动了logcat,你可以通过-v选项来指定输出格式:
[adb]logcat[-vformat]
下面是用thread来产生的日志格式:
adblogcat-vthread
需要注意的是你只能-v选项来规定输出格式option.
4~~~~~~~~~~~Logcat命令列表
-bbuffer加载一个可使用的日志缓冲区供查看,比如event和radio.默认值是main。
具体查看ViewingAlternativeLogBuffers.
-c清楚屏幕上的日志.
-d输出日志到屏幕上.
-ffilename指定输出日志信息的filename,默认是stdout.-g输出指定的日志缓冲区,输出后退出.
-ncount设置日志的最大数目count.,默认值是4,需要和-r选项一起使用。
-rkbytes每kbytes时输出日志,默认值为16,需要和-f选项一起使用.-s设置默认的过滤级别为silent.
-vformat设置日志输入格式,默认的是brief格式,要知道更多的支持的格式,参看ControllingLogOutputFormat
adbbugreport-returnallinformationfromthedevicethatshouldbeincludedinabugreport.
adbshelldmesg查询内核缓冲区信息
adbshelldumpstate各类信息,比如进程信息,内存信息,进程是否异常,kernnel的log等
adbshelldumpcrash
adbshelldumpsys查询所有service的状态
-----------其他-----------
模拟器使用镜像sdcard
用SDK里的mksdcard工具来创建FAT32磁盘镜像并在模拟器启动时加载它。
这样创建镜像:
?
mksdcardsizefile,
比如我要创建一个64M的SD卡模拟文件,文件路径是在
D:
\workspace\sdcard.img
mksdcard***-*****D:
\workspace\sdcard.img
EmulatorCsdcardD:
\workspace\sdcard.img
或者在eclipse的run菜单的openrundialog对话框中配置启动参数。
#top
Usage:
top[-mmax_procs][-niterations][-ddelay][-ssort_column]
[-t][-h]
-mnumMaximumnumberofprocessestodisplay.
-nnumUpdatestoshowbeforeexiting.
-dnumSecondstowaitbetweenupdates.
-scolColumntosortby(cpu,vss,rss,thr).
-tShowthreadsinsteadofprocesses.
-hDisplaythishelpscreen.
*********simpleselection******************selectionbylist*********
-Aallprocesses-Cbycommandname
-Nnegateselection-GbyrealgroupID(supportsnames)
-aallw/ttyexceptsessionleaders-UbyrealuserID(supportsnames)-dallexceptsessionleaders-gbysessionORbyeffectivegroupname
-eallprocesses-pbyprocessID
Tallprocessesonthisterminal-sprocessesinthesessionsgivenaallw/tty,includingotherusers-tbytty
g*****E--DONOTUSE-ubyeffectiveuserID(supportsnames)
ronlyrunningprocessesUprocessesforspecifiedusersxprocessesw/ocontrollingttystbytty
***********outputformat*********************longoptions***********
-o,ouser-defined-ffull--Group--User--pid--cols--ppid-j,jjobcontrolssignal--group--user--sid--rows--info-O,Opreloaded-ovvirtualmemory--cumulative--format--deselect-l,llonguuser-oriented--sort--tty--forest--version-FextrafullXregisters--heading--no-heading--context*********miscoptions*********
-V,VshowversionLlistformatcodesfASCIIartforest-m,m,-L,-T,HthreadsSchildreninsum-ychange-lformat-M,Zsecuritydatactruecommandname-cschedulingclass-w,wwideoutputnnumericWCHAN,UID-Hprocesshierarchy
netstat-ano查看网络连状态
显示协议统计信息和当前TCP/IP网络连接。
*****[-a][-b][-e][-n][-o][-pproto][-r][-s][-v][interval]
-a显示所有连接和监听端口。
-b显示包含于创建每个连接或监听端口的
可执行组件。
在某些情况下已知可执行组件
拥有多个独立组件,并且在这些情况下
包含于创建连接或监听端口的组件序列
被显示。
这种情况下,可执行组件名
在底部的[]中,顶部是其调用的组件,
等等,直到TCP/IP部分。
注意此选项
可能需要很长时间,如果没有足够权限
可能失败。
-e显示以太网统计信息。
此选项可以与-s
选项组合使用。
-n以数字形式显示地址和端口号。
-o显示与每个连接相关的所属进程ID。
-pproto显示proto指定的协议的连接;proto可以是
下列协议之一:
TCP、UDP、TCPv6或UDPv6。
如果与-s选项一起使用以显示按协议统计信息,proto可以是下列协议之一:
IP、IPv6、ICMP、ICMPv6、TCP、TCPv6、UDP或UDPv6。
-r显示路由表。
-s显示按协议统计信息。
默认地,显示IP、
IPv6、ICMP、ICMPv6、TCP、TCPv6、UDP和UDPv6的统计信息;
-p选项用于指定默认情况的子集。
-v与-b选项一起使用时将显示包含于
为所有可执行组件创建连接或监听端口的
组件。
interval重新显示选定统计信息,每次显示之间
暂停时间间隔(以秒计)。
按CTRL+C停止重新
显示统计信息。
如果省略,netstat显示当前
配置信息(只显示一次)
pm
usage:
pm[list|path|install|uninstall]
pmlistpackages[-f]
pmlistpermission-groups
pmlistpermissions[-g][-f][-d][-u][GROUP]
pmlistinstrumentation[-f][TARGET-*****]
pmlistfeatures
pmpath*****
pminstall[-l][-r][-t][-i*****ER_*****_NAME]PATH
pmuninstall[-k]*****
pmenable*****_OR_*****NT
pmdisable*****_OR_*****NT
Thelistpackagescommandprintsallpackages.Options:
-f:
seetheirassociatedfile.
Thelistpermission-groupscommandprintsallknown
permissiongroups.
Thelistpermissionscommandprintsallknown
permissions,optionallyonlythoseinGROUP.Options:
-g:
organizebygroup.
-f:
printallinformation.
-s:
shortsummary.
-d:
onlylistdangerouspermissions.
-u:
listonlythepermissionsuserswillsee.
Thelistinstrumentationcommandprintsallinstrumentations,oronlythosethattargetaspecifiedpackage.Options:
-f:
seetheirassociatedfile.
Thelistfeaturescommandprintsallfeaturesofthesystem.
Thepathcommandprintsthepathtothe.apkofapackage.
Theinstallcommandinstallsapackagetothesystem.Options:
-l:
installthepackagewith*****_LOCK.
-r:
reinstallanexisitingapp,keepingitsdata.
-t:
allowtest.apkstobeinstalled.
-i:
specifytheinstallerpackagename.
Theuninstallcommandremovesapackagefromthesystem.Options:
-k:
keepthedataandcachedirectoriesaround.
afterthepackageremoval.
Theenableanddisablecommandschangetheenabledstateofagivenpackageorcomponent(writtenas“package/class").
查看stdout和stderr
在默认状态下,Android系统有stdout和stderr(System.out和System.err)输出到/dev/null,
在运行DalvikVM的进程中,有一个系统可以备份日志文件。
在这种情况下,系统会用stdout和stderr和优先级I.来记录日志信息
通过这种方法指定输出的路径,停止运行的模拟器/设备,然后通过用setprop命令远程输入日志
$adbshellstop
$adbshellsetproplog.redirect-stdiotrue
$adbshellstart系统直到你关闭模拟器/设备前设置会一直保留,可以通过添加/data/local.prop可以使用模拟器/设备上的默认设置
UI/软件试验程序Monkey
当Monkey程序在模拟器或设备运行的时候,如果用户出发了比如点击,触摸,手势或一些系统级别的事件的时候,
它就会产生随机脉冲,所以可以用Monkey用随机重复的方法去负荷测试你开发的软件.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ADB 常用命令