最近给一台新的mac机器配置Android自动化测试环境,包含: adb环境、android sdk等。
adb命令主要用途: 查看log日志、查看手机文件、查看内存等。
特此重新记录下adb环境安装和adb常用命令操作。
install brew: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
install adb : brew cask install android-platform-tools
use adb: adb devices
echo 'export PATH=$PATH:~/.android-sdk-macosx/platform-tools/' >> ~/.bash_profile
source ~/.bash_profile

原理图
当启动 adb 客户端时,客户端首先检查 adb 服务端进程是否运行,如果没有运行,则启动服务端。当服务端启动时,它会绑定到本地的 TCP5037 端口,并且监听从 adb 客户端发来的命令——所有 adb 客户端都使用 5037 端口与 adb 服务端通信。
接下来服务端与所有正在运行的模拟器或手机连接。它通过扫描 5555-5585 之间的奇数号端口来搜索模拟器或手机,一旦发现 adb 守护进程,就通过此端口进行连接。需要说明的是,每一个模拟器或手机使用一对有序的端口,偶数号端口用于控制台连接,奇数号端口用于 adb 连接。
adb shell getprop ro.build.version.release
out:6.0
adb shell pm list packages com.xueqiu.android
out: package:com.xueqiu.android
adb wait-for-device
adb shell echo ping
adb shell dumpsys package io.appium.settings
out: more app infomation
adb shell getprop ro.build.version.sdk
out:23
包名/启动类
adb shell am start -W -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'
-S是强行关闭app参数
adb shell am start -W -n com.xueqiu.android/.view.WelcomeActivityAlias -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000
appops set io.appium.settings android\:mock_location allow
adb install UnicodeIME-debug.apk
adb shell settings get secure default_input_method
out:io.appium.android.ime/.UnicodeIME
adb shell ime enable io.appium.android.ime/.UnicodeIME'
adb shell wm size
out:Physical size: 480x800
adb shell getprop ro.product.model
out:Samsung Galaxy S6 - 6.0.0 - API 23 - 1440x2560
adb shell getprop ro.product.manufacturer
out:Genymotion
adb shell am force-stop com.xueqiu.android
adb shell pm clear com.xueqiu.android
adb forward tcp:4724 tcp:4724
adb push 本地文件路径/手机设备文件夹路径
push /usr/local/lib/node_modules/appium/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/
adb shell ps
out:
shell 2757 268 698820 59108 ep_poll f731dd75 S com.android.shell
u0_a61 2791 268 1209988 198016 ep_poll f731dd75 S com.xueqiu.android
u0_a61 2844 268 1114452 125092 ep_poll f731dd75 S com.xueqiu.android:pushservice
adb shell dumpsys window
out:
Surface: shown=true layer=21015 alpha=1.0 rect=(0.0,0.0) 480.0 x 800.0
Window #2 Window{b1145d7 u0 com.xueqiu.android/com.xueqiu.android.common.MainActivity}:
input keyevent 3 home键
input keyevent 4 back键
adb logcat -v time -n 20 -r 10240 -f /sdcard/log/note.log &