Android adb常用命令
adb是什么
Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components.
i. A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as DDMS also create adb clients.
ii. A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
iii. A daemon, which runs as a background process on each emulator or device instance.
看到篇文章可以熟悉一下 adb 源碼分析
adb的全稱為Android Debug Bridge,就是起到調(diào)試橋的作用
adb是android sdk里的一個(gè)工具, 用這個(gè)工具可以直接操作管理android模擬器或者真實(shí)的andriod設(shè)備.有三部分組件:
i. 一個(gè)客戶端,它運(yùn)行在您的開發(fā)環(huán)境上。你可以通過一個(gè)終端來使用adb命令。如其他Android DDMS工具也是創(chuàng)建一個(gè)adb客戶端。
ii.一個(gè)服務(wù)器,它作為一個(gè)后臺(tái)進(jìn)程運(yùn)行在您的開發(fā)環(huán)境上。服務(wù)器管理客戶端和adb進(jìn)程運(yùn)行在模擬器/設(shè)備之間的通信。
iii.一個(gè)進(jìn)程,作為后臺(tái)進(jìn)程運(yùn)行在模擬器/設(shè)備的實(shí)例。
adb常用的一些命令
adb命令用于自動(dòng)化測(cè)試中,將為Android測(cè)試帶來很大的便利。
- 查看幫助
adb或adb help - 獲取應(yīng)用啟動(dòng)項(xiàng)
adb shell monkey -p 包名 -c android.intent.category.LAUNCHER -v -v 0 | grep Using - 獲取當(dāng)前activity
adb shell dumpsys activity activities | grep mFocusedActivity
adb shell dumpsys window | grep mCurrent - 獲取包安裝路徑
adb shell pm path 包名 - 開啟-結(jié)束adb服務(wù)
adb start-serveradb kill-server - 獲取設(shè)備列表信息
adb devices
操作多臺(tái)設(shè)備時(shí),adb -s <設(shè)備序列號(hào)> + <命令> - 重啟手機(jī)
adb reboot - 獲取設(shè)備狀態(tài)
adb get-statedevices:正常連接,offline:無響應(yīng),unknown:沒有連接設(shè)備 - 獲取手機(jī)mac地址
adb shell cat /sys/class/net/wlan0/address - 手機(jī)CPU序列號(hào)
adb shell cat /proc/cpuinfo - 卸載apk
adb uninstall <package name>例:adb uninstall com.ex.example - 卸載apk,但保留數(shù)據(jù)
adb uninstall -k <package name> - 安裝apk
adb install <apk file>
例:adb install example.apk保證apk路徑無誤。 - 保留數(shù)據(jù),重新安裝apk
adb install -r <apk file> - 系統(tǒng)日志
adb logcatadb logcat > d:\logcat.log - bugreport
adb bugreportadb bugreport > d:\bugreport.log
打印dumpsys、dumpstate、logcat的輸出,也是用于分析錯(cuò)誤 - 復(fù)制文件到本地
adb pull sdcard/1.txt d:\ - 推送文件到設(shè)備
adb push d:\1.txt sdcard/ - 無線連接設(shè)備
usb連上設(shè)備后,
查看設(shè)備的ip:adb shell ifconfig wlan0
wlan0: ip 192.168.20.10 mask 255.255.254.0 flags [up broadcast running multicast]
adb tcpip 5555
log:restarting in TCP mode port: 5555
adb connect 192.168.20.10:5555
提示 connected to 192.168.20.64:5555 就可以拔掉usb了,
切換回usbadb usb - adb shell 包含太多內(nèi)容
啟動(dòng)應(yīng)用
adb shell am start -n <package_name>/<activity_class_name>例:adb shell am start -n com.ex.example/com.example.activity.WelcomActivityNew
列出系統(tǒng)應(yīng)用adb shell pm list package
列出第三方應(yīng)用adb shell pm list package -s
列出apk包的位置adb shell pm path com.ex.example
adb shell psadb shell top - adb 輸入、滑動(dòng)等操作
輸入域操作adb shell input <string>
物理鍵操作adb shell input keyevent <key code number or name>
keyevent指的是android對(duì)應(yīng)的keycode,比如home鍵的keycode=3,back鍵的keycode=4
點(diǎn)擊操作adb shell input tap <x> <y>(x,y)坐標(biāo)
滑動(dòng)操作adb shell input swipe <x1> <y1> <x2> <y2> - cpu值
adb shell dumpsys cpuinfo
adb shell dumpsys cpuinfo |grep packagename
adb shell top -n 1| grep PackageName - 獲取內(nèi)存
adb shell dumpsys meminfo
adb shell dumpsys meminfo pakagename or Pid - 獲取流量
adb shell cat /proc/Pid/net/devPid為進(jìn)程id - 截圖
adb shell /system/bin/screencap -p /sdcard/screen01.png
adb pull /sdcard/screen01.png E:\11ss - 屏幕錄制
adb shell screenrecord /sdcard/record.mp4
adb pulll /sdcard/record.mp4 - 給app賦權(quán)限
adb shell pm grant cn.com.weshare.jiekuan android.permission.INTERNET - 發(fā)送按鍵事件
adb shell input keyevent KEYCODE_HOME67 退格 3 home - 對(duì)屏幕發(fā)送一個(gè)觸摸事件
adb shell input tap 500 500 - 滑動(dòng)事件
adb shell input swipe 300 300 300 900