ADB詳細命令集

來源:互聯網
上載者:User

ADB全稱Android Debug Bridge, 是android sdk裡的一個工具, 用這個工具可以直接操作管理android模擬器或者真實的andriod裝置(如G1手機).
它的主要功能有:

    * 運行裝置的shell(命令列)
    * 管理模擬器或裝置的連接埠映射
    * 電腦和裝置之間上傳/下載檔案
    * 將本地apk軟體安裝至模擬器或android裝置

ADB是一個 用戶端-伺服器端 程式, 其中用戶端是你用來操作的電腦, 伺服器端是android裝置..
先說安裝方法, 電腦上需要安裝用戶端. 用戶端包含在sdk裡. 裝置上不需要安裝, 只需要在手機上開啟選項settings-applications-development-USB debugging.
對於Mac和Linux使用者, 下載好的sdk解壓後, 可以放~或者任意目錄. 然後修改~/.bash_profile檔案, 設定運行環境指向sdk的tools目錄.
具體是開啟~/.bash_profile檔案(如果沒有此檔案也可以自行添加), 在裡面加入一行:
export PATH=${PATH}:<你的sdk目錄>/tools
然後就可以使用adb命令了.
嫌安裝麻煩的同學其實也可以省去上面安裝步驟, 直接輸入完整路徑來使用命令。
對於windows xp使用者, 需要先安裝usb驅動 android_usb_windows.zip, 然後如果你只打算使用adb而不想下載整個sdk的話, 可以下載這個單獨的adb工具包 adb_win.zip 下載後解壓, 把裡面 adb.exe 和 AdbWinApi.dll 兩個檔案放到系統硬碟的 windows/system32 檔案夾裡就可以了
現在說下ADB常用的幾個命令
查看裝置

    * adb devices

這個命令是查看當前串連的裝置, 串連到電腦的android裝置或者模擬器將會列出顯示
安裝軟體

    * adb install <apk檔案路徑>

這個命令將指定的apk檔案安裝到裝置上.
卸載軟體

    * adb uninstall <軟體名>
    * adb uninstall -k <軟體名>

如果加 -k 參數,為卸載軟體但是保留配置和快取檔案.
登入裝置shell

    * adb shell
    * adb shell <command命令>

這個命令將登入裝置的shell.
後面加<command命令>將是直接運行裝置命令, 相當於執行遠程命令
從電腦上傳送檔案到裝置

    * adb push <本地路徑> <遠程路徑>

用push命令可以把本機電腦上的檔案或者檔案夾複製到裝置(手機)
從裝置上下載檔案到電腦

    * adb pull <遠程路徑> <本地路徑>

用pull命令可以把裝置(手機)上的檔案或者檔案夾複製到本機電腦
顯示協助資訊

    * adb help

這個命令將顯示協助資訊

這裡還有一個英文版的:
在DOS下輸入以下命令基本可以完成刷機任務,一些常用命令解釋如下:

    adb devices - 列出串連到電腦的ADB裝置(也就是手機),一般顯示出手機P/N碼.如果沒有顯示出來則手機與電腦沒有串連上.
    adb install <packagename.apk> – 安裝手機軟體到手機中,如:adb install qq2009.apk.
    adb remount – 重新開啟手機寫入模式(刷機模式).
    adb push <localfile> <location on your phone> - 傳送檔案到手機中,如:adb push recovery.img /sdcard/recovery.img,將本地目錄中的recovery.img檔案傳送手機的SD卡中並取同樣的檔案名稱.
    adb pull <location on your phone> <localfile> - 傳送手機的檔案到本地目錄(和上命令相反).
    adb shell <command> - 讓手機執行命令,<command>就是手機執行的命令.如: adb shell flash_image recovery /sd-card/recovery-RAv1.0G.img,執行將recovery-RAv1.0G.img寫入到recovery 區中.

我們刷recovery時一般按下順序執行:

    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

其它的自己靈活運用了.
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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.