连接
adb connect host:port
安装apk到客户端
adb install install.apk
覆盖已安装包
adb install -r install.apk
将调试信息注入源码
const-string/jumbo v9, "mytestcode"
invoke-static {v9, v6}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I
自动编绎apk并安装apk到设备
- 用
apktool b 源码目录
命令对源文件打包 - 用
signapk.jar
对打包后的apk进行签名 - 用
adb install
将签名后的apk安装到android设备中
写个sh脚本,内容以下:
#打包apk
apktool b ../
echo "sign apk...";
#用signapk签名apk
java -jar ~/android/signapk/signapk.jar ~/android/signapk/testkey.x509.pem ~/android/signapk/testkey.pk8 app-Wapseo4-release-7.5.10.apk lmbang7_5_10_signapk.apk
echo "adb install apk..."
#安装apk到设备,前提是设备已连接,加` -r`覆盖安装
adb install -r lmbang7_5_10_signapk.apk
用adb logcat 打印调试信息
adb logcat | grep mytestcode
只显示自定义的调试标签
也可以将调试信息追加到文件里
adb logcat | grep myestcode >> ~/android/apk/log/logcat.log
显示设备当前界面所在activity
adb shell dumpsys activity top | grep ACTIVITY
点击退回按钮
adb shell input keyevent 3
或
adb shell input keyevent BACK
打开设置界面
adb shell am start -n com.android.settings/.Settings
关闭指定的应用
adb shell am force-stop com.some.package
旋转屏幕
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1
i后面跟的不同的值代表旋转为不同的方向,取值范围为0,1,2,3
获取系统版本
adb shell getprop ro.build.version.release
to get API level:
adb shell getprop ro.build.version.sdk
You can see all available properties with this command:
adb shell getprop
或
adb shell cat /system/build.prop
设置adbd为开机启动
setprop persist.adb.tcp.port 5555
ADB over USB might not be available after reboot. To undo this setting, do:
setprop persist.adb.tcp.port ""
开启adb
setprop service.adb.tcp.port 5555
stop adbd
start adbd
让/system 等系统目录可读写
adb disable-verity
adb remount
模拟从上往上滑动屏幕
adb shell input swipe 100 1000 100 200
模拟点击屏幕坐标
adb shell input tap 500 1000
调小音量
input keyevent 25
开启/关闭静音
静音关闭状态下会开启静音
静音开启状态下会关闭静音
input keyevent 164
按键对照表
常量 | 名称 | 值 |
---|---|---|
KEYCODE_CALL | 拨号键 | 5 |
KEYCODE_ENDCALL | 挂机键 | 6 |
KEYCODE_HOME | 按键Home | 3 |
KEYCODE_MENU | 菜单键 | 82 |
KEYCODE_BACK | 返回键 | 4 |
KEYCODE_SEARCH | 搜索键 | 84 |
KEYCODE_CAMERA | 拍照键 | 27 |
KEYCODE_FOCUS | 拍照对焦键 | 80 |
KEYCODE_POWER | 电源键 | 26 |
KEYCODE_NOTIFICATION | 通知键 | 83 |
KEYCODE_MUTE | 话筒静音键 | 91 |
KEYCODE_VOLUME_MUTE | 扬声器静音键 | 164 |
KEYCODE_VOLUME_UP | 音量增加键 | 24 |
KEYCODE_VOLUME_DOWN | 音量减小键 | 25 |
查看分辨率
adb shell wm size
或
adb shell dumpsys window displays
结果:
WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)
Display: mDisplayId=0
init=1920x1080 160dpi cur=1920x1080 app=1920x1080 rng=1080x1055-1920x1895
deferred=false layoutNeeded=false
mStacks[1]1
mStackId=1
mDeferDetach=false
{taskId=10 appTokens=[AppWindowToken{737d9f5 token=Token{2bc0f2df ActivityRecord{33b12d7e u0 com.android.settings/.Settings t10}}}, AppWindowToken{29b962a0 token=Token{25c46fa3 ActivityRecord{2c3d52d2 u0 com.android.settings/.SubSettings t10}}}, AppWindowToken{19df3cfc token=Token{38a209ef ActivityRecord{333af6ce u0 com.android.settings/.SubSettings t10}}}] mdr=false}
mStacks[0]0
mStackId=0
mDeferDetach=false
{taskId=3 appTokens=[AppWindowToken{4711398 token=Token{2e8e97b ActivityRecord{492ad0a u0 com.softwinner.launcher/.Launcher t3}}}] mdr=false}
Application tokens in top down Z order:
mStackId=1
mTaskId=10
Activity #2 AppWindowToken{19df3cfc token=Token{38a209ef ActivityRecord{333af6ce u0 com.android.settings/.SubSettings t10}}}:
windows=[Window{3f0ab100 u0 com.android.settings/com.android.settings.SubSettings}]
windowType=2 hidden=false hasVisible=true
app=true voiceInteraction=false
allAppWindows=[Window{3f0ab100 u0 com.android.settings/com.android.settings.SubSettings}]
groupId=10 appFullscreen=true requestedOrientation=-1
hiddenRequested=false clientHidden=false willBeHidden=false reportedDrawn=true reportedVisible=true
numInterestingWindows=1 numDrawnWindows=1 inPendingTransaction=false allDrawn=true (animator=true)
startingData=null removed=false firstWindowDrawn=true mDeferRemoval=false
Activity #1 AppWindowToken{29b962a0 token=Token{25c46fa3 ActivityRecord{2c3d52d2 u0 com.android.settings/.SubSettings t10}}}:
windows=[Window{e86a564 u0 com.android.settings/com.android.settings.SubSettings}]
windowType=2 hidden=true hasVisible=true
app=true voiceInteraction=false
allAppWindows=[Window{e86a564 u0 com.android.settings/com.android.settings.SubSettings}]
groupId=10 appFullscreen=true requestedOrientation=-1
hiddenRequested=true clientHidden=true willBeHidden=false reportedDrawn=false reportedVisible=false
numInterestingWindows=1 numDrawnWindows=1 inPendingTransaction=false allDrawn=true (animator=true)
startingData=null removed=false firstWindowDrawn=true mDeferRemoval=false
Activity #0 AppWindowToken{737d9f5 token=Token{2bc0f2df ActivityRecord{33b12d7e u0 com.android.settings/.Settings t10}}}:
windows=[Window{8226ca5 u0 com.android.settings/com.android.settings.Settings}]
windowType=2 hidden=true hasVisible=true
app=true voiceInteraction=false
allAppWindows=[Window{8226ca5 u0 com.android.settings/com.android.settings.Settings}]
groupId=10 appFullscreen=true requestedOrientation=-1
hiddenRequested=true clientHidden=true willBeHidden=false reportedDrawn=false reportedVisible=false
numInterestingWindows=1 numDrawnWindows=1 inPendingTransaction=false allDrawn=true (animator=true)
startingData=null removed=false firstWindowDrawn=true mDeferRemoval=false
mStackId=0
mTaskId=3
Activity #0 AppWindowToken{4711398 token=Token{2e8e97b ActivityRecord{492ad0a u0 com.softwinner.launcher/.Launcher t3}}}:
windows=[Window{212c88ca u0 com.softwinner.launcher/com.softwinner.launcher.Launcher}]
windowType=2 hidden=true hasVisible=true
app=true voiceInteraction=false
allAppWindows=[Window{212c88ca u0 com.softwinner.launcher/com.softwinner.launcher.Launcher}]
groupId=3 appFullscreen=true requestedOrientation=-1
hiddenRequested=true clientHidden=true willBeHidden=false reportedDrawn=false reportedVisible=false
numInterestingWindows=1 numDrawnWindows=1 inPendingTransaction=false allDrawn=true (animator=true)
startingData=null removed=false firstWindowDrawn=true mDeferRemoval=false
打开浏览器url
am start -a android.intent.action.VIEW -d http://www.china.com
打开浏览器
am start -n com.android.browser/com.android.browser.BrowserActivity
重启设备
$ reboot
模拟长按屏幕
adb shell input swipe 100 100 100 100 1000
在 100 100 100 100 的位置长按1000毫秒
用 monkey 指令打开应用(不需指定 activitiy name)
monkey -p com.cube_y.expbox -c android.intent.category.LAUNCHER 1
com.cube_y.expbox 可以通过 pm list package
查得
截图/截屏
adb shell /system/bin/screencap -p /sdcard/screenshot.png