ADB(Android Debug Bridge) 命令详解
本帖最后由 loadbxh 于 2018-1-20 17:54 编辑ADB(Android Debug Bridge)命令详解
1.介绍
Android设备与PC主机通过USB/TYPE-C And 网络连接,并与PC主机进行通讯/调试工具.
1.1源文档Doc:
Android Debug Bridge version 1.0.39
Version 0.0.1-4500957
Installed as C:\Windows\system32\adb.exe
global options:
-a listen on all network interfaces, not just localhost
-d use USB device (error if multiple devices connected)
-e use TCP/IP device (error if multiple TCP/IP devices available)
-s SERIALuse device with given serial (overrides $ANDROID_SERIAL)
-t ID use device with given transport id
-H name of adb server host
-P port of adb server
-L SOCKETlisten on given socket for adb server
general commands:
devices [-l] list connected devices (-l for long output)
help show this help message
version show version num
networking:
connect HOST[:PORT] connect to a device via TCP/IP
disconnect ]
disconnect from given TCP/IP device , or all
forward --list list all forward socket connections
forward [--no-rebind] LOCAL REMOTE
forward socket connection using:
tcp:<port> (<local> may be "tcp:0" to pick any open port)
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)
forward --remove LOCAL remove specific forward socket connection
forward --remove-all remove all forward socket connections
ppp TTY run PPP over USB
reverse --list list all reverse socket connections from device
reverse [--no-rebind] REMOTE LOCAL
reverse socket connection using:
tcp:<port> (<remote> may be "tcp:0" to pick any open port)
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
reverse --remove REMOTEremove specific reverse socket connection
reverse --remove-all remove all reverse socket connections from device
file transfer:
push [--sync] LOCAL... REMOTE
copy local files/directories to device
--sync: only push files that are newer on the host than the device
pull [-a] REMOTE... LOCAL
copy files/dirs from device
-a: preserve file timestamp and mode
sync
sync a local build from $ANDROID_PRODUCT_OUT to the device (default all)
-l: list but don't copy
shell:
shell [-e ESCAPE] [-n] [-Tt] [-x]
run remote shell command (interactive shell if no command given)
-e: choose escape character, or "none"; default '~'
-n: don't read from stdin
-T: disable PTY allocation
-t: force PTY allocation
-x: disable remote exit codes and stdout/stderr separation
emu COMMAND run emulator console command
app installation:
install [-lrtsdg] PACKAGE
install-multiple [-lrtsdpg] PACKAGE...
push package(s) to the device and install them
-l: forward lock application
-r: replace existing application
-t: allow test packages
-s: install application on sdcard
-d: allow version code downgrade (debuggable packages only)
-p: partial application install (install-multiple only)
-g: grant all runtime permissions
uninstall [-k] PACKAGE
remove this app package from the device
'-k': keep the data and cache directories
backup/restore:
to show usage run "adb shell bu help"
debugging:
bugreport
write bugreport to given PATH ;
if PATH is a directory, the bug report is saved in that directory.
devices that don't support zipped bug reports output to stdout.
jdwp list pids of processes hosting a JDWP transport
logcat show device log (logcat --help for more)
security:
disable-verity disable dm-verity checking on userdebug builds
enable-verity re-enable dm-verity checking on userdebug builds
keygen FILE
generate adb public/private key; private key stored in FILE,
public key stored in FILE.pub (existing files overwritten)
scripting:
wait-for[-TRANSPORT]-STATE
wait for device to be in the given state
State: device, recovery, sideload, or bootloader
Transport: usb, local, or any
get-state print offline | bootloader | device
get-serialno print <serial-number>
get-devpath print <device-path>
remount
remount /system, /vendor, and /oem partitions read-write
reboot
reboot the device; defaults to booting system image but
supports bootloader and recovery too. sideload reboots
into recovery and automatically starts sideload mode,
sideload-auto-reboot is the same but reboots after sideloading.
sideload OTAPACKAGE sideload the given full OTA package
root restart adbd with root permissions
unroot restart adbd without root permissions
usb restart adb server listening on USB
tcpip PORT restart adb server listening on TCP on PORT
internal debugging:
start-server ensure that there is a server running
kill-server kill the server if it is running
reconnect kick connection from host side to force reconnect
reconnect device kick connection from device side to force reconnect
reconnect offline reset offline/unauthorized devices to force reconnect
environment variables:
$ADB_TRACE
comma-separated list of debug info to log:
all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp
$ADB_VENDOR_KEYS colon-separated list of keys (files or directories)
$ANDROID_SERIAL serial number to connect to (see -s)
$ANDROID_LOG_TAGS tags to be used by logcat (see logcat --help)
2.基础信息解释:
Android Debug Bridge version 1.0.39
# 使用版本为1.0.39 的 Android Debug Bridge
Version 0.0.1-4500957
# 内部版本为 0.0.1-4500957
Installed as C:\Windows\system32\adb.exe
# 安装路径为 C:\Windows\system32\adb.exe
# 此处说明:
# 1.从https://dl.google.com/android/repository/platform-tools-latest-平台.zip,下载Google开放ADB工具到合适你的运行平台.
# 2.解压platform-tools-latest-平台.zip,释放出ADB相关文件到路径: C:\Windows\system32\
# 3.打开系统path配置.修改系统PATH,在PATH最后一个分号后添加C:\Windows\system32\adb并保存.重启!
# 4.测试ADB PATH,打开CMD输入 adb version
3.基础操作:
adb 参数
# 参数:a 监听所有网络端口,d USB连接,e TCP连接,s 序列号连接,t ID连接,usb 监听USB连接,tcpip 监听TCP连接
# 作用:连接主机
connect 或disconnect
# 参数: 主机IP:端口
# 作用:从网络连接设备
reconnect
# 参数:device 设备端强制重连,offline 重置ADB授权请求
# 作用:强制重连
wait-for[-参数]-STATE
# 参数:device,bootloader,recovery,sideload(后面STATE不用理会)
# 作用:等待'参数'设备接入
get-state
# 参数:null
# 作用:获取设备名称
get-serialno
# 参数:null
# 作用:获取设备序列号
get-devpath
# 参数:null
# 作用:获取开发版本
start-server
# 参数:null
# 作用:开启ABD
kill-server
# 参数:null
# 作用:关闭ADB
reboot
# 参数:bootloader,recovery,sideload,sideload-auto-reboot
# 作用:重启设备到状态
4.常用操作
logcat
# 参数:配合shell符号参数
# 作用:输出设备日志
bugreport
# 参数: PATH
# 作用:输出设备日志文件
push 参数1 参数2 --sync
# 参数:本地路径 远程路径 !注意权限
# 作用:将本地文件拷贝至远程设备,sync参数为更新文件
pull 参数1 参数2 -a
# 参数:远程路径 本地路径
# 作用:将设备文件拷贝至本地路径,a参数保留文件时间戳等信息.
shell 参数
# 参数:e 转义字符,n 禁止读取,x 仿真控制台
# 作用:远程shell仿真
remount
# 参数: 分区
# 作用:重载分区
install
# 参数:l 锁定应用,r 取代应用,t 允许测试包,s 安装在外部存储,d 允许版本降级,p 批量安装,g 授予所有运行时权限
# 作用:安装/调试应用
uninstall
# 参数: k 保留数据
# 作用:卸载应用
论坛编辑器不会用,暂时就写这木多吧,手打翻译.实机测试.如果觉得辛苦请点赞收藏.
嗯,想起一件事,前几天看到有人问Fastboot.我这里也发一点吧,fastboot太接近核心.随便乱用我不负责的哦!
手机重启到Fastboot模式下.连接手机.输入Fastboot确认状态OK
fastboot flash boot xxx.img
这个命令可以给设备刷入BOOT分区,常用.但是注意你的Recovery和设备处理器平台.(OEM可不喜欢你这样,给你下套的多了去,自己注意)
根据这个命令,你可以结合ADB shell mount结果,对任何分区进行提取 修改 刷写操作.
fastboot erase boot
这个命令,可以擦除Mount出来的各个分区数据.这个擦除不是覆写.只是Clear.会让分区归零.所以用过后不做写入操作,基本设备都不会开机.如果你直接擦出了BOOT那么恭喜你.制造黑砖一块.Fastboot,recovery统统报废.
还有一个不是Fastboot的方式,就是ADB sideload.这个命令也是可以刷机的,而且相对更安全.但是时间长,具体的怎么操作自己找找资料吧,我要去煮晚饭了...
斑竹,帖子位置不对帮忙移动一下.看我ID信息就知道,我不常来论坛的.但是我是一个灰常热心的人.
看不懂,大神级别 寒尘丶Coldust 发表于 2018-1-22 00:15
感觉像是从官网上扒下来的...adb很强大 不过最好希望有人能做一份chm手册就最好了
是的,就是扒的官方文档.ADB其实也只是个调试通道而已,别想太多,真正强悍的是Android的Linux特性. 感谢分享!!!!! 留个脚印 很详细了,过去玩安卓的时候一直搞不懂,现在懂了却已经退烧了 学习学习,感谢分享 看的那么多,就几个回复的,诶 费心了,楼主! 感谢分享 好像没必要发吧?Android官网就有技术文档
页:
[1]
2