ADB全稱Android Debug Bridge, 是android sdk里的一個(gè)工具, 用這個(gè)工具可以直接操作管理android模擬器或者真實(shí)的andriod設(shè)備(如G1手機(jī)).
它的主要功能有:
* 運(yùn)行設(shè)備的shell(命令行)
* 管理模擬器或設(shè)備的端口映射
* 計(jì)算機(jī)和設(shè)備之間上傳/下載文件
* 將本地apk軟件安裝至模擬器或android設(shè)備
ADB是一個(gè) 客戶端-服務(wù)器端 程序, 其中客戶端是你用來操作的電腦, 服務(wù)器端是android設(shè)備..
先說安裝方法, 電腦上需要安裝客戶端. 客戶端包含在sdk里. 設(shè)備上不需要安裝, 只需要在手機(jī)上打開選項(xiàng)settings-applications-development-USB debugging.
對(duì)于Mac和Linux用戶, 下載好的sdk解壓后, 可以放~或者任意目錄. 然后修改~/.bash_profile文件, 設(shè)置運(yùn)行環(huán)境指向sdk的tools目錄.
具體是打開~/.bash_profile文件(如果沒有此文件也可以自行添加), 在里面加入一行:
export PATH=${PATH}:你的sdk目錄>/tools
然后就可以使用adb命令了.
嫌安裝麻煩的同學(xué)其實(shí)也可以省去上面安裝步驟, 直接輸入完整路徑來使用命令。
對(duì)于windows xp用戶, 需要先安裝usb驅(qū)動(dòng) android_usb_windows.zip, 然后如果你只打算使用adb而不想下載整個(gè)sdk的話, 可以下載這個(gè)單獨(dú)的adb工具包 adb_win.zip 下載后解壓, 把里面 adb.exe 和 AdbWinApi.dll 兩個(gè)文件放到系統(tǒng)盤的 windows/system32 文件夾里就可以了
現(xiàn)在說下ADB常用的幾個(gè)命令
查看設(shè)備
* adb devices
這個(gè)命令是查看當(dāng)前連接的設(shè)備, 連接到計(jì)算機(jī)的android設(shè)備或者模擬器將會(huì)列出顯示
安裝軟件
* adb install apk文件路徑>
這個(gè)命令將指定的apk文件安裝到設(shè)備上.
卸載軟件
* adb uninstall 軟件名>
* adb uninstall -k 軟件名>
如果加 -k 參數(shù),為卸載軟件但是保留配置和緩存文件.
登錄設(shè)備shell
* adb shell
* adb shell command命令>
這個(gè)命令將登錄設(shè)備的shell.
后面加command命令>將是直接運(yùn)行設(shè)備命令, 相當(dāng)于執(zhí)行遠(yuǎn)程命令
從電腦上發(fā)送文件到設(shè)備
* adb push 本地路徑> 遠(yuǎn)程路徑>
用push命令可以把本機(jī)電腦上的文件或者文件夾復(fù)制到設(shè)備(手機(jī))
從設(shè)備上下載文件到電腦
* adb pull 遠(yuǎn)程路徑> 本地路徑>
用pull命令可以把設(shè)備(手機(jī))上的文件或者文件夾復(fù)制到本機(jī)電腦
顯示幫助信息
* adb help
這個(gè)命令將顯示幫助信息
這里還有一個(gè)英文版的:
在DOS下輸入以下命令基本可以完成刷機(jī)任務(wù),一些常用命令解釋如下:
adb devices - 列出連接到電腦的ADB設(shè)備(也就是手機(jī)),一般顯示出手機(jī)P/N碼.如果沒有顯示出來則手機(jī)與電腦沒有連接上.
adb install packagename.apk> – 安裝手機(jī)軟件到手機(jī)中,如:adb install qq2009.apk.
adb remount – 重新打開手機(jī)寫模式(刷機(jī)模式).
adb push localfile> location on your phone> - 傳送文件到手機(jī)中,如:adb push recovery.img /sdcard/recovery.img,將本地目錄中的recovery.img文件傳送手機(jī)的SD卡中并取同樣的文件名.
adb pull location on your phone> localfile> - 傳送手機(jī)的文件到本地目錄(和上命令相反).
adb shell command> - 讓手機(jī)執(zhí)行命令,command>就是手機(jī)執(zhí)行的命令.如: adb shell flash_image recovery /sd-card/recovery-RAv1.0G.img,執(zhí)行將recovery-RAv1.0G.img寫入到recovery 區(qū)中.
我們刷recovery時(shí)一般按下順序執(zhí)行:
adb shell mount -a
adb push recovery-RAv1.0G.img /system/recovery.img
adb push recovery-RAv1.0G.img /sdcard/recovery-RAv1.0G.img
adb shell flash_image recovery /sdcard/recovery-RAv1.0G.img reboot
其它的自己靈活運(yùn)用了.
ADB命令詳解:
Android Debug Bridge version 1.0.20
-d - directs command to the only connected USB device returns an error if more than one USB device is present.
-e - directs command to the only running emulator.returns an error if more than one emulator is running.
-s serial number> – directs command to the USB device or emulator withthe given serial number
-p product name or path> – simple product name like ’sooner’, or a relative/absolute path to a product out directory like ‘out/target/product/sooner’.
If -p is not specified, the ANDROID_PRODUCT_OUT environment variable is used, which must be an absolute path.
devices – list all connected devices
device commands:
adb push local> remote> – copy file/dir to device
adb pull remote> local> – copy file/dir from device
adb sync [ directory> ] – copy host->device only if changed (see ‘adb help all’)
adb shell – run remote shell interactively
adb shell command> – run remote shell command
adb emu command> – run emulator console command
adb logcat [ filter-spec> ] – View device log
adb forward local> remote> – forward socket connections
forward specs are one of:
tcp: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)
adb jdwp – list PIDs of processes hosting a JDWP transport
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 bugreport – return all information from the device that should be included in a bug report.
adb help – show this help message
adb version – show version num
DATAOPTS:
(no option) – don’t touch the data partition
-w – wipe the data partition
-d – flash the data partition
scripting:
adb wait-for-device – block until device is online
adb start-server – ensure that there is a server running
adb kill-server – kill the server if it is running
adb get-state – prints: offline | bootloader | device
adb get-serialno – prints: serial-number>
adb status-window – continuously print device status for a specified device
adb remount – remounts the /system partition on the device re
ad-write
adb root – restarts adb with root permissions
networking:
adb ppp tty> [parameters] – Run PPP over USB.
Note: you should not automatically start a PDP connection.
tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
[parameters] – Eg. defaultroute debug dump local notty usepeerdns
adb sync notes: adb sync [ directory> ]
localdir> can be interpreted in several ways:
- If directory> is not specified, both /system and /data partitions will be updated.
- If it is “system” or “data”, only the corresponding partition is updated