android adb常用命令
阿新 • • 發佈:2019-01-25
下面是一些我搜集的一些Android ADB(Android Debug Bridge)命令,在手動或自動構建和測試過程中它們非常好用。
檢視已連線的裝置
使用此命令檢視所有的連線裝置,並列出它們的ID:
1 |
adb
devices
|
如果存在多個裝置連線,可以使用 adb -s DEVICE_ID
來指定特定的裝置。
安裝應用
使用 install
命令來安裝apk,如果裝置上已經安裝了應用,可以使用可選引數 -r
重新進行安裝並保留所有資料。
1 2 3 4 |
adb
install
-r APK_FILE
#
example adb
install
-r com.growingwiththeweb.example
|
解除安裝應用
1 2 3 4 |
adb
uninstall PACKAGE_NAME
#
example
adb
uninstall com.growingwiththeweb.example
|
啟動Activity
1 2 3 4 5 6 |
adb
shell am start PACKAGE_NAME /ACTIVITY_IN_PACKAGE
adb
shell am start PACKAGE_NAME /FULLY_QUALIFIED_ACTIVITY #
example
adb
shell am start -n com.growingwiththeweb.example/.MainActivity
adb
shell am start -n com.growingwiththeweb.example /com .growingwiththeweb.example.MainActivity
|
進入裝置的命令列
1 |
adb
shell
|
擷取螢幕
Sergei Shvetsov 寫出了一行漂亮的PERL程式碼,它利用 shell screencap截圖並輸出到本地目錄中,訪問他的部落格獲取詳細資訊。
1 |
adb
shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g'
> screen .png
|
解鎖螢幕
向裝置傳送螢幕解鎖命令:
1 |
adb
shell input keyevent 82
|
日誌
用來在命令列中顯示日誌流:
1 |
adb
logcat
|
按標籤名過濾
1 2 3 4 5 6 |
adb
logcat -s TAG_NAME
adb
logcat -s TAG_NAME_1 TAG_NAME_2
#
example
adb
logcat -s TEST
adb
logcat -s TEST MYAPP
|
按優先順序過濾
顯示指定告警優先順序及以上的日誌:
1 2 3 4 |
adb
logcat "*:PRIORITY"
#
example
adb
logcat "*:W"
|
優先順序設定如下:
- V:Verbose (最低優先順序)
- D:Debug
- I:Info
- W:Warning
- E:Error
- F:Fatal
- S:Silent (最高優先順序, 在這個級別上不會列印任何資訊))
按標籤名和優先順序過濾
1 2 3 4 |
adb
logcat -s TAG_NAME:PRIORITY
adb
logcat -s TAG_NAME_1:PRIORITY TAG_NAME_2:PRIORITY`
#
example
adb
logcat -s TEST: W
|
使用grep過濾
另外,在支援grep
的系統中,logcat
輸出可以通過管道傳送給grep
:
1 2 3 4 5 6 |
adb
logcat | grep
"SEARCH_TERM"
adb
logcat | grep
"SEARCH_TERM_1\|SEARCH_TERM_2"
#
example
adb
logcat | grep
"Excepti
|