命令行工具ADB
时间:2010-08-31 来源:朱宇华
命令行工具ADB(Andvoid Debug Bridge)是Android提供的一个通用的调试工具,借助这个工具,我们可以管理设备或手机模拟器的状态。51Testing软件测试网Pr"VVU)wDy#v
51Testing软件测试网1r(n9XX*vZb
adb help51Testing软件测试网)vt!~)H4C;C$K!S~O
51Testing软件测试网6Hh2S9H"Nm9se"?l4o
AndroidDebugBridgeversion 1.0.2051Testing软件测试网N/V0S3{l|POv
Oq*KQVBr:n3JXhS0
-d - directs command to the only connected USB device51Testing软件测试网v AxyPI
returns an error if more than one USB device is present.51Testing软件测试网K n0M,^gW4Z%Drf
-e - directs command to the only running emulator.51Testing软件测试网:l%|o$o"^
returns an error if more than one emulator is running.51Testing软件测试网N(qf1{o-B
-s <serial number> - directs command to the USB device or emulator with
2eLj*lUR@+y9\0the given serial number51Testing软件测试网.Z(`4hyT/bK
-p <product name or path> - simple product name like 'sooner', or51Testing软件测试网n6G*Sh"F @ct
a relative/absolute path to a product51Testing软件测试网pBUmE7t4E1h'O)t
out directory like 'out/target/product/sooner'.51Testing软件测试网3gb6M)A}
If -p is not specified, the ANDROID_PRODUCT_OUT51Testing软件测试网$cxL1V]
environment variable is used, which must51Testing软件测试网(x$y+x'a3v:XEh
be an absolute path.
cIo0L&I3H3c0L8Vo0devices - list all connected devices
N^'c]c.aWUb0$N~WR|\)p0
device commands:
VG5FTvG%[p;CW0adb push <local> <remote> - copy file/dir to device51Testing软件测试网"\f!L WD
adb pull <remote> <local> - copy file/dir from device
3i8qh1wR)U{8h}D;Y0adb sync [ <directory> ] - copy host->device only if changed51Testing软件测试网r2Ac d?lQ(oD
(see 'adb help all')
v.QH`&VT0adb shell - run remote shell interactively
/I/Y+v!d)pm6qz0adb shell <command> - run remote shell command51Testing软件测试网#r#R%o/c}dj&Vr&f
adb emu <command> - run emulator console command51Testing软件测试网+H+E5B9ZN O
adb logcat [ <filter-spec> ] - View device log51Testing软件测试网4?^H'K;_(A@9x
adb forward <local> <remote> - forward socket connections
~-F7C5Wu2rlt;Ho {0forward specs are one of:
cI uqd4h:r0tcp:<port>51Testing软件测试网jQ+e N+s&s
localabstract:<unix domain socket name>
t8s(Im[G6Q$e0localreserved:<unix domain socket name>51Testing软件测试网+`"|2K6^!z'v*Q
localfilesystem:<unix domain socket name>51Testing软件测试网m"P*nTww.B
dev:<character device name>
A;C1q5Wv1`F.s0jdwp:<process pid> (remote only)
4^)X7}ilG4CXc0adb jdwp - list PIDs of processes hosting a JDWP transport51Testing软件测试网nmwa"?}@T/_
adb install [-l] [-r] <file> - push this package file to the device and install it51Testing软件测试网%}0[A P8S
('-l' means forward-lock the app)
s1}*@I1}6}U$`(Z[0('-r' means reinstall the app, keeping its data)
3ty!l&f^GM8wHp){ [+d0adb uninstall [-k] <package> - remove this app package from the device
)q,RtU)_G3~'H0('-k' means keep the data and cache directories)51Testing软件测试网E%Y:HVH,xFa
adb bugreport - return all information from the device
(kHs1Mm;t5Kl{0that should be included in a bug report.51Testing软件测试网_!XGR;x Rv&BU
51Testing软件测试网pt+Su0dA'O
adb help - show this help message51Testing软件测试网5d3K2G3s'V3M
adb version - show version num
"_(hM*a cX W+b%L#R%j0G)t4Z+L H't0
DATAOPTS:
F%cg3At*YQaJ0(no option) - don't touch the data partition
DfB:p7fX0-w - wipe the data partition
ry.a@OAA4] \8c%[ t0-d - flash the data partition51Testing软件测试网4?\{^Kw3n&Qg
7}9uU2{FQ"m0
scripting:
Ej*Zfv&S0adb wait-for-device - block until device is online51Testing软件测试网 SSj/ju
adb start-server - ensure that there is a server running
!}@"g-A.Vds q0adb kill-server - kill the server if it is running51Testing软件测试网%GU$r9nz+~@"G
adb get-state - prints: offline | bootloader | device
!E#|j?wG$u'W1jo7h*F0adb get-product - prints: <product-id>
;|*L;S4{2@0adb get-serialno - prints: <serial-number>51Testing软件测试网 Z]uIsao(BT?
adb status-window - continuously print device status for a specified device
JI@-gVS}1U0adb remount - remounts the /system partition on the device read-write
|(_EwYS'E}0bU!v!k k1li0
networking:51Testing软件测试网OKM:aoL(D
adb ppp <tty> [parameters] - Run PPP over USB.51Testing软件测试网{ecrN)l:`/g rY
Note: you should not automatically start a PDP connection.
!KMQA{X0<tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty151Testing软件测试网 S8oIczO_AP2pC zo
[parameters] - Eg. defaultroute debug dump local notty usepeerdns
G4B A9P E0{+[`;xP1k0{W)ETu6Ac0
adb sync notes: adb sync [ <directory> ]51Testing软件测试网q k3Pz&x9rv0k(h
<localdir> can be interpreted in several ways:51Testing软件测试网7e8V-t)dF!x~ K
51Testing软件测试网%V7PS Af:y$z
- If <directory> is not specified, both /system and /data partitions will be updated.51Testing软件测试网(V?9Xv8d
51Testing软件测试网WXl)N1Djk
- If it is "system" or "data", only the corresponding partition51Testing软件测试网-{vx.UY0o_s
is updated.
gU(r,iftw:D051Testing软件测试网l f;K/{#RP
51Testing软件测试网QCrD/l)Kts
ADB还可以进行以下的操作:
j b*W'Yq-?01、快速更新设备或手机模拟器中的代码,如应用或Android系统升级;
9W?$?bQ UfG#s02、在设备上运行shell命令;51Testing软件测试网)X$U#N(Zg(@
3、管理设备或手机模拟器上的预定端口;51Testing软件测试网/y{z(gV:RO
4、在设备或手机模拟器上复制或粘贴文件;
2x6u$P/is05、安装.apk文件到仿真器上。51Testing软件测试网"L-nj1V/UD
51Testing软件测试网)IMCc#|pcw/L
以下为一些常用的操作:
Amc YkK${5\6`01、安装应用到模拟器:51Testing软件测试网md2H/ZwRD2V'j
adb install
\E7B'v k6Z%sUi%~B0比较郁闷的是,Android并没有提供一个卸载应用的命令,只能自己手动删除:51Testing软件测试网(b&qM&H:Gmb'fK
adb shell51Testing软件测试网8^S5YmEM;X*OE
cd /data/app
k h3niMR^;o0rm app.apk51Testing软件测试网W,q7HXp F2}
Q%E'K2Wv2H8`7F0
2、进入设备或模拟器的shell:51Testing软件测试网(SA2Ucb,W
adb shell
K zcGk0通过上面的命令,就可以进入设备或模拟器的shell环境中,在这个Linux Shell中,你可以执行各种Linux的命令,另外如果只想执行一条shell命令,可以采用以下的方式:
.K,m)|Y5e3V0adb shell [command]51Testing软件测试网*K.C)h]d
如:adb shell dmesg会打印出内核的调试信息。
9`og$E$G+yl"|-^[051Testing软件测试网Y8r\*^__XS
3、发布端口:51Testing软件测试网r8uM![%| I8?.G
你可以设置任意的端口号,做为主机向模拟器或设备的请求端口。如:51Testing软件测试网*C5Oy'X r@ v
adb forward tcp:5555 tcp:8000
oWC%p-uu2T5uD051Testing软件测试网u[3zg"V5aK k`Yt
4、复制文件:51Testing软件测试网2f [y^*Y
你可向一个设备或从一个设备中复制文件,51Testing软件测试网'AEI!}{tL
复制一个文件或目录到设备或模拟器上:51Testing软件测试网 ~5L yW1jqDjt;R!Z
adb push51Testing软件测试网djrzu?h
如:adb push test.txt /tmp/test.txt51Testing软件测试网$\W!``8J-R.m1Lf0}n-[
从设备或模拟器上复制一个文件或目录:51Testing软件测试网;l0U)iPh4}3c7vl3M
adb pull51Testing软件测试网4C$a}6w#n
如:adb pull /addroid/lib/libwebcore.so .51Testing软件测试网V0|3\8US
#@7@+EG.D\Et$x0
5、搜索模拟器/设备的实例:
tmcKHH&h1J0取得当前运行的模拟器/设备的实例的列表及每个实例的状态:51Testing软件测试网r(v"Z2v"y5rc
adb devices
WG.gPvQ&wD-UQ%K%W051Testing软件测试网];W/kVmx
6、查看bug报告:
Y9x0Pl1N0adb bugreport
'sd f?([ u@!E0.mu:A"V H0
7、记录无线通讯日志:
Hh*U7l.D&Q$]t0一般来说,无线通讯的日志非常多,在运行时没必要去记录,但我们还是可以通过命令,设置记录:
|gK9JfC)s8t0bf0adb shell51Testing软件测试网;[e0k#OnJ cS;j
logcat -b radio51Testing软件测试网t$wneG:{9c6T
4|yA c|t0
8、获取设备的ID和序列号:
NI]n fJ~0adb get-product
4SE+NK$K.g0adb get-serialno51Testing软件测试网@9n%^F S&x
,N/c)Z9t/~7Ov_,t3@0
9、访问数据库SQLite351Testing软件测试网XN-Gz]Q5wT3u
adb shell
zD~M/Z9t|Yt0sqlite3
q,M1y R4gE0