ADB命令簡(jiǎn)介ADB是一個(gè)功能強(qiáng)大的命令行工具。通過(guò)它可以直接和模擬器或真機(jī)進(jìn)行交互。它是一個(gè)具有客戶端和服務(wù)器端的程序。 它主要由三個(gè)部分組成:
當(dāng)你啟動(dòng)一個(gè)adb客戶端的時(shí)候,客戶端會(huì)首先檢測(cè)是否已經(jīng)有adb服務(wù)進(jìn)程運(yùn)行,如果沒有運(yùn)行,那么它會(huì)首先啟動(dòng)一個(gè)服務(wù)進(jìn)程,當(dāng)服務(wù)進(jìn)程啟動(dòng)后,服務(wù)進(jìn)程綁定本地的5037端口,并且監(jiān)聽所有來(lái)自adb 客戶端的命令,所有的adb客戶端通過(guò)5037與adb 服務(wù)端進(jìn)行交互。 服務(wù)端運(yùn)行之后與所有運(yùn)行的模擬器或真機(jī)建立鏈接,它通過(guò)一組范圍從5555 到5585的奇數(shù)的端口檢索到所有的模擬器或真機(jī)。每一臺(tái)模擬器或真機(jī)需要獲取一對(duì)連續(xù)的端口,偶數(shù)端口用于控制臺(tái)的鏈接,奇數(shù)端口用于adb的鏈接。 當(dāng)然,如果你用Eclipse開發(fā),并且也安裝了ADT插件,那么你沒必要通過(guò)adb命令行與模擬器或真機(jī)交互,ADT插件已經(jīng)完美的將adb整合進(jìn)了Eclipse IDE.當(dāng)然還是提倡多使用adb命令行,這樣的話比較方便自定義debug方法,同時(shí)也可以更好的理解其工作原理。 Adb命令列表下列表格列出了adb支持的命令,并對(duì)它們的意義和使用方法做了說(shuō)明.
adb命令參數(shù)詳解 # adb --helpAndroid Debug Bridge version 1.0.29 -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 - directs command to the USB device or emulator with the given serial number. Overrides ANDROID_SERIAL environment variable. -p - 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 connect [:] - connect to a device via TCP/IP Port 5555 is used by default if no port number is specified. disconnect [[:]] - disconnect from a TCP/IP device. Port 5555 is used by default if no port number is specified. Using this command with no additional arguments will disconnect from all connected TCP/IP devices.device commands: adb push - copy file/dir to device adb pull [] - copy file/dir from device adb sync [ ] - copy host->device only if changed (-l means list but don't copy) (see 'adb help all') adb shell - run remote shell interactively adb shell - run remote shell command adb emu - run emulator console command adb logcat [ ] - View device log adb forward - forward socket connections forward specs are one of: tcp: localabstract: localreserved: localfilesystem: dev: jdwp: (remote only) adb jdwp - list PIDs of processes hosting a JDWP transport adb install [-l] [-r] [-s] [--algo --key --iv ] - push this package file to the device and install it ('-l' means forward-lock the app) ('-r' means reinstall the app, keeping its data) ('-s' means install on SD card instead of internal storage) ('--algo', '--key', and '--iv' mean the file is encrypted already) adb uninstall [-k] - 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 backup [-f ] [-apk|-noapk] [-shared|-noshared] [-all] [-system|-nosystem] [] - write an archive of the device's data to . If no -f option is supplied then the data is written to 'backup.ab' in the current directory. (-apk|-noapk enable/disable backup of the .apks themselves in the archive; the default is noapk.) (-shared|-noshared enable/disable backup of the device's shared storage / SD card contents; the default is noshared.) (-all means to back up all installed applications) (-system|-nosystem toggles whether -all automatically includes system applications; the default is to include system apps) ( is the list of applications to be backed up. If the -all or -shared flags are passed, then the package list is optional. Applications explicitly given on the command line will be included even if -nosystem would ordinarily cause them to be omitted.) adb restore - restore device contents from the backup archive adb help - show this help message adb version - show version numscripting: 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: adb status-window - continuously print device status for a specified device adb remount - remounts the /system partition on the device read-write adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program adb reboot-bootloader - reboots the device into the bootloader adb root - restarts the adbd daemon with root permissions adb usb - restarts the adbd daemon listening on USB adb tcpip - restarts the adbd daemon listening on TCP on the specified portnetworking: adb ppp [parameters] - Run PPP over USB. Note: you should not automatically start a PPP connection. refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1 [parameters] - Eg. defaultroute debug dump local notty usepeerdnsadb sync notes: adb sync [ ] can be interpreted in several ways: - If is not specified, both /system and /data partitions will be updated. - If it is 'system' or 'data', only the corresponding partition is updated.environmental variables: ADB_TRACE - Print debug information. A comma separated list of the following values 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp ANDROID_SERIAL - The serial number to connect to. -s takes priority over this if given. ANDROID_LOG_TAGS - When used with the logcat option, only these debug tags are printed. 查看所有當(dāng)前通過(guò)USB設(shè)備連接的設(shè)備 # adb devicesList of devices attachedemulator-5554 device0288424641407417 deviceHT9CRP810308 device 指定某一個(gè)模擬器或真機(jī) # adb -s emulator-5554 shell 打印日志 # adb logcat 上傳一個(gè)文件 # adb push ./sina_login.png /mnt/sdcard/DCIM/Camera/sina_login.png 上傳一個(gè)目錄 # adb push ./emo /mnt/sdcard/DCIM/Camera/emo 下載一個(gè)文件 # adb pull /mnt/sdcard/DCIM/Camera/IMG_20121130_102210.jpg ./IMG_20121130_102210.jpg280 KB/s (24741 bytes in 0.086s) 下載一個(gè)目錄,這里不用設(shè)置遞歸參數(shù)-R,而且空目錄沒有下載下來(lái) # adb pull /mnt/sdcard/GigaTalk ./GigaTalk 安裝APK # adb install BigramPaid.apk1872 KB/s (30541229 bytes in 15.930s) pkg: /data/local/tmp/BigramPaid.apk 指定安裝到SD卡 # adb install -s BigramPaid.apk2262 KB/s (30541229 bytes in 13.180s) pkg: /sdcard/tmp/BigramPaid.apkSuccess 再次安裝,提示錯(cuò)誤信息:已安裝 # adb install -s BigramPaid.apk2322 KB/s (30541229 bytes in 12.839s) pkg: /sdcard/tmp/BigramPaid.apkFailure [INSTALL_FAILED_ALREADY_EXISTS] 重新安裝,保留原有數(shù)據(jù),允許共用包名及數(shù)字簽名 # adb install -r BigramPaid.apk2526 KB/s (30541229 bytes in 11.806s) pkg: /data/local/tmp/BigramPaid.apk 保留數(shù)據(jù)以及緩存目錄 # adb uninstall com.gigabud.bigram 重新加載/system 分區(qū) # adb remountremount succeeded 安裝APK過(guò)程中常見的一些錯(cuò)誤信息 int INSTALL_FAILED_ALREADY_EXISTS //程序已經(jīng)存在int INSTALL_FAILED_CONFLICTING_PROVIDER //存在同名的內(nèi)容提供者int INSTALL_FAILED_DEXOPT //dex優(yōu)化驗(yàn)證失敗int INSTALL_FAILED_DUPLICATE_PACKAGE //已存在同名程序int INSTALL_FAILED_INSUFFICIENT_STORAGE //沒有足夠的存儲(chǔ)空間int INSTALL_FAILED_INVALID_APK //無(wú)效的APKint INSTALL_FAILED_INVALID_URI //無(wú)效的鏈接int INSTALL_FAILED_MISSING_SHARED_LIBRARY //需求的共享庫(kù)已丟失int INSTALL_FAILED_NO_SHARED_USER //要求的共享用戶不存在int INSTALL_FAILED_OLDER_SDK //系統(tǒng)版本過(guò)舊int INSTALL_FAILED_REPLACE_COULDNT_DELETEint INSTALL_FAILED_SHARED_USER_INCOMPATIBLE //需求的共享用戶簽名錯(cuò)誤int INSTALL_FAILED_UPDATE_INCOMPATIBLE //版本不能共存int INSTALL_PARSE_FAILED_BAD_MANIFEST //錯(cuò)誤的MANIFEST配置文件int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME //錯(cuò)誤的包名int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID //錯(cuò)誤的共享用戶int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING //證書編碼無(wú)效int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES //證書不一致int INSTALL_PARSE_FAILED_MANIFEST_EMPTY //MANIFEST配置文件為空int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED //MANIFEST配置文件非法int INSTALL_PARSE_FAILED_NOT_APK //不是有效的APK文件int INSTALL_PARSE_FAILED_NO_CERTIFICATES //無(wú)認(rèn)證證書int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION //異常int INSTALL_SUCCEEDED //安裝成功int REPLACE_EXISTING_PACKAGE //包名已存在 啟用logcat日志 Android日志系統(tǒng)提供了記錄和查看系統(tǒng)調(diào)試信息的功能。日志都是從各種軟件和一些系統(tǒng)的緩沖區(qū)中記錄下來(lái)的,緩沖區(qū)可以通過(guò) Logcat命令列表
使用logcat命令 你可以用 [adb] logcat [ 請(qǐng)查看Listing of logcat Command Options ,它對(duì)logcat命令有詳細(xì)的描述 . 你也可以在你的電腦或運(yùn)行在模擬器/設(shè)備上的遠(yuǎn)程adb shell端來(lái)使用 $ adb logcat //logcat 過(guò)濾日志輸出每一個(gè)輸出的Android日志信息都有一個(gè)標(biāo)簽和它的優(yōu)先級(jí).
在運(yùn)行l(wèi)ogcat的時(shí)候在前兩列的信息中你就可以看到 下面是一個(gè)logcat輸出的例子,它的優(yōu)先級(jí)就似乎I,標(biāo)簽就是ActivityManage: I/ActivityManager( 585): Starting activity: Intent { action=android.intent.action...} 為了讓日志輸出能體現(xiàn)管理的級(jí)別,你還可以用過(guò)濾器來(lái)控制日志輸出,過(guò)濾器可以幫助你描述系統(tǒng)的標(biāo)簽等級(jí). 過(guò)濾器語(yǔ)句按照下面的格式描 從上面的tag的信息中可以得到日志的優(yōu)先級(jí). 你可以在過(guò)濾器中多次寫 這些說(shuō)明都只到空白結(jié)束。 下面有一個(gè)列子,例子表示支持所有的日志信息,除了那些標(biāo)簽為”ActivityManager”和優(yōu)先級(jí)為”Info”以上的和標(biāo)簽為” MyApp”和優(yōu)先級(jí)為” Debug”以上的。 小等級(jí),優(yōu)先權(quán)報(bào)告為tag. adb logcat ActivityManager:I MyApp:D *:S 上面表達(dá)式的最后的元素 下面的過(guò)濾語(yǔ)句指顯示優(yōu)先級(jí)為warning或更高的日志信息: adb logcat *:W 控制日志輸出格式日志信息包括了許多元數(shù)據(jù)域包括標(biāo)簽和優(yōu)先級(jí)。 修改日志的輸出格式,可以顯示出特定的元數(shù)據(jù)域。可以通過(guò)
當(dāng)啟動(dòng)了 [adb] logcat [-v 下面是用 adb logcat -v thread 需要注意的是你只能 查看可用日志緩沖區(qū)Android日志系統(tǒng)有循環(huán)緩沖區(qū),并不是所有的日志系統(tǒng)都有默認(rèn)循環(huán)緩沖區(qū)。 為了得到日志信息,你需要通過(guò)
[adb] logcat [-b 下面的例子表示怎么查看日志緩沖區(qū)包含radio 和 telephony信息: adb logcat -b radio 不完全匯總
|
|