adb全名Andorid Debug Bridge. 直接翻譯安卓調(diào)試橋,環(huán)境變量中配置好adb的環(huán)境變量纸镊,直接通過命令行可以省很多事胁勺。
配置好環(huán)境變量直接 win+X(win10)快捷鍵打開命令提示符,輸入adb 或者 adb help 打印所有提示信息侨颈,如圖。
Android Debug Bridge version 1.0.26
-d - directs command to the only connected USB device
returns an error if more than one USB device is present.
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 with
the given serial number. Overrides ANDROID_SERIAL
environment variable.
-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
connect <host>:<port> - connect to a device via TCP/IP
disconnect <host>:<port> - disconnect from a TCP/IP device
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] [-s] <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)
('-s' means install on SD card instead of internal storage)
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 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 <port> - restarts the adbd daemon listening on TCP on the specified port
networking:
adb ppp <tty> [parameters] - Run PPP over USB.
Note: you should not automatically start a PPP 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.
adb shell 命令
adb 命令和 adb shell 命令 芯义。
簡(jiǎn)單點(diǎn)講哈垢,adb 命令是 adb 這個(gè)程序自帶的一些命令,而 adb shell 進(jìn)入目標(biāo)設(shè)備的Linux Shell環(huán)境, 在該環(huán)境中可以執(zhí)行一些Linux命令.
pm list package
列出安裝在設(shè)備上的應(yīng)用 不帶任何選項(xiàng):列出所有的應(yīng)用的包名
adb shell pm list package
-s:列出系統(tǒng)應(yīng)用
adb shell pm list package -s
-3:列出第三方應(yīng)用
adb shell pm list package -3
-f:列出應(yīng)用包名及對(duì)應(yīng)的apk名及存放位置
adb shell pm list package -f
-i:列出應(yīng)用包名及其安裝來源扛拨,結(jié)果顯示例子:
adb shell pm list package -i
package:com.zhihu.android installer=com.xiaomi.market
install 安裝命令 pm install , 安裝應(yīng)用
目標(biāo) apk 存放于 PC 端耘分,請(qǐng)用 adb install 安裝(adb install apk路徑)
目標(biāo) apk 存放于 Android 設(shè)備上,請(qǐng)用 pm install 安裝
pm uninstall , 卸載應(yīng)用绑警,同 adb uninstall , 后面跟的參數(shù)都是應(yīng)用的包名
pm clear , 清除應(yīng)用數(shù)據(jù)
pm set-install-location , pm get-install-location , 設(shè)置應(yīng)用安裝位置求泰,獲取應(yīng)用安裝位置
am
am start , 啟動(dòng)一個(gè) Activity,已啟動(dòng)系統(tǒng)相機(jī)應(yīng)用為例
啟動(dòng)相機(jī)
adb shell am start -n com.android.camera/.Camera
Starting: Intent { cmp=com.android.camera/.Camera }
先停止目標(biāo)應(yīng)用计盒,再啟動(dòng)
adb shell am start -S com.android.camera/.Camera
Stopping: com.android.camera
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.camera/.Camera }
等待應(yīng)用完成啟動(dòng)
adb shell am start -W com.android.camera/.Camera
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.camera/.Camera }
Status: ok
Activity: com.android.camera/.Camera
ThisTime: 500
TotalTime: 500
Complete
啟動(dòng)默認(rèn)瀏覽器打開一個(gè)網(wǎng)頁(yè)
adb shell am start -a android.intent.action.VIEW -d http://baidu.com
Starting: Intent { act=android.intent.action.VIEW dat=http://baidu.com }
啟動(dòng)撥號(hào)器撥打 10086
adb shell am start -a android.intent.action.CALL -d tel:10086
Starting: Intent { act=android.intent.action.CALL dat=tel:xxxxx }
am force-stop , 后跟包名渴频,結(jié)束應(yīng)用
input
這個(gè)命令可以向 Android 設(shè)備發(fā)送按鍵事件,其源碼 Input.java
-
input text , 發(fā)送文本內(nèi)容章郁,不能發(fā)送中文
adb shell input text test123456
前提先將鍵盤設(shè)置為英文鍵盤
-
input keyevent , 發(fā)送按鍵事件枉氮,KeyEvent.java
adb shell input keyevent KEYCODE_HOME
模擬按下 Home 鍵 志衍,源碼里面有定義:
public static final int KEYCODE_HOME = 3;
因此可以將命令中的
KEYCODE_HOME
替換為3
-
input tap , 對(duì)屏幕發(fā)送一個(gè)觸摸事件
adb shell input tap 500 500
點(diǎn)擊屏幕上坐標(biāo)為 500 500 的位置
-
input swipe , 滑動(dòng)事件
adb shell input swipe 900 500 100 500
從右往左滑動(dòng)屏幕
如果版本不低于 4.4 , 可以模擬長(zhǎng)按事件
adb shell input swipe 500 500 501 501 2000
其實(shí)就是在小的距離內(nèi),在較長(zhǎng)的持續(xù)時(shí)間內(nèi)進(jìn)行滑動(dòng)聊替,最后表現(xiàn)出來的結(jié)果就是長(zhǎng)按動(dòng)作
screencap截圖命令
adb shell screencap -p /sdcard/screen.png
截屏楼肪,保存至 sdcard 目錄
screenrecord4.4 新增的錄制命令
adb shell screenrecord sdcard/record.mp4
執(zhí)行命令后操作手機(jī),ctrl + c 結(jié)束錄制惹悄,錄制結(jié)果保存至 sdcard
ime輸入法春叫,Ime.java
列出設(shè)備上的輸入法
adb shell ime list -s
com.google.android.inputmethod.pinyin/.PinyinIME
com.baidu.input_mi/.ImeService
選擇輸入法
adb shell ime set com.baidu.input_mi/.ImeService
Input method com.baidu.input_mi/.ImeService selected
wm Wm.java 獲取設(shè)備分辨率
adb shell wm size
Physical size: 1080x1920
getprop
查看 Android 設(shè)備的參數(shù)信息,只運(yùn)行 adb shell getprop泣港,結(jié)果以 key : value 鍵值對(duì)的形式顯示暂殖,如要獲取某個(gè) key 的值:
獲取設(shè)備的 sdk 版本
adb shell getprop ro.build.version.sdk