Android常用adb调试命令

常用调试命令


前言

记录一下自己常用的adb 调试命令


Android开发少不了adb命令调试,熟练使用adb命令可以更方便对系统及应用进行调试分析

1、查看当前设备连接
adb devices
2、adb服务重启
adb kill-server
adb start-server
3、抓取log
抓取实时log,并输出到log.txt文件中
adb shell logcat >  log.txt
抓取开机log
adb wait-for-device && adb logcat > log.txt
抓取小部分log
adb logcat -d > log.txt

若是报找不到logcat相关命令,加上shell, adb shell logcat

4、抓取驱动Kernel log

在Android系统中,printk输出的日志信息保存在/proc/kmsg中,使用查看命令

 adb shell cat /proc/kmsg  | grep "alarm" //grep "alarm"表示只抓取alarm的信息

或者:

USER-NAME@MACHINE-NAME:~/Android$ adb shell

root@android:/ # cat  /proc/kmsg | grep "alarm" //grep "alarm"表示只抓取alarm的信息

输出保存到文件中

adb shell dmesg > demsg.txt
5、查看当前启动的应用activity
adb shell  
logcat | grep "START u0" 
或者
adb shell dumpsys activity activities  查看当前的ResumedActivity
6、输入相关的keycode,模拟按键
power按键
adb shell input keyevent 26

home按键
adb shell input keyevent 3

相对应的按键值可以通过查看KeyEvent.java
7、查看当前设备分辨率等
D:\>adb shell
bengal:/ $ wm size
Physical size: 480x800
bengal:/ $ wm density
Physical density: 240
手动修改系统分辨率及密度
bengal:/ $ wm size 720x1080
bengal:/ $ wm density 360
修改后查看
bengal:/ $ wm size
Physical size: 480x800
Override size: 720x1080
bengal:/ $ wm density
Physical density: 240
Override density: 360
还原系统默认设置
bengal:/ $ wm size reset
bengal:/ $ wm density reset
8、启动activity
 adb shell am start pkgname/activityname 
 或者通过action隐式启动
 启动浏览器 :
 am start -a android.intent.action.VIEW -d 
9、发送广播
adb shell am broadcast [options] <INTENT>
作用:发送一个广播
举例:adb shell am broadcast -a "send_my_test_broadcast" (发送一个名叫send_my_test_broadcast的广播)
举例:adb shell am broadcast -a android.intent.action.MASTER_CLEAR(恢复出厂设置的方法,会清除内存所有内容)
举例:adb shell am broadcast -n com.application.test/.MyBroadcast
10、系统settins,prop数据库

获取手机的setting provider值

adb shell settings
Settings provider (settings) commands:
  help
      Print this help text.
  get [--user <USER_ID> | current] NAMESPACE KEY
      Retrieve the current value of KEY.
  put [--user <USER_ID> | current] NAMESPACE KEY VALUE [TAG] [default]
      Change the contents of KEY to VALUE.
      TAG to associate with the setting.
      {default} to set as the default, case-insensitive only for global/secure namespace
  delete [--user <USER_ID> | current] NAMESPACE KEY
      Delete the entry for KEY.
  reset [--user <USER_ID> | current] NAMESPACE {PACKAGE_NAME | RESET_MODE}
      Reset the global/secure table for a package with mode.
      RESET_MODE is one of {untrusted_defaults, untrusted_clear, trusted_defaults}, case-insensitive
  list [--user <USER_ID> | current] NAMESPACE
      Print all defined keys.
      NAMESPACE is one of {system, secure, global}, case-insensitive
 

例如获取所有system保存的值

adb shell settings list system
accelerometer_rotation=0
dim_screen=1
dtmf_tone=1
dtmf_tone_type=0
end_button_behavior=2
font_scale=1.0
haptic_feedback_enabled=1
hearing_aid=0
hide_rotation_lock_toggle_for_accessibility=0
lockscreen_sounds_enabled=1
mode_ringer_streams_affected=422
mute_streams_affected=111
notification_light_pulse=1
notification_sound=content://media/internal/audio/media/138?title=Pixie%20Dust&canonical=1
notification_sound_set=1
pointer_speed=0
radio.data.stall.recovery.action=0
ringtone=content://media/internal/audio/media/88?title=Flutey%20Phone&canonical=1
ringtone_set=1
screen_brightness=102

单独获取及设置某个属性值

获取屏幕亮度值
D:\>adb shell settings get system screen_brightness
102

设置屏幕亮度为160
D:\>adb shell settings put system screen_brightness 160

system一般是需要系统权限,一般应用使用secure,global,可查看相对应保存的值

获取手机prop值

adb shell getprop
adb shell getprop "xxxxx" 获取"xxxxx"所保存的值

adb shell setprop "vendor.test.value" 66  //设置prop "vendor.test.value"的值为66
11、系统应用调试

调试系统应用需要root设备

adb root
adb remount

Android P,Q,R remount 失败需要先取消验证 
go to setting -> system -> Developer options -> OEM unlocking
adb reboot bootloader
fastboot flashing unlock
press volume up key
fastboot reboot
adb root
adb disable-verity
adb reboot
adb root
adb remount

注意:AndroidR OTA升级需要在enable-verity状态下进行,adb disable-verity 后push apk后,再执行adb enable-verity会把还原系统,push的apk会被还原

替换应用

adb root
adb remount
adb push out\target\product\xxx\system\system_ext\priv-app\SearchLauncherQuickStep\SearchLauncherQuickStep.apk /system/system_ext/priv-app/SearchLauncherQuickStep

有些可以push完后直接杀进程,有些需要重启,稳妥一些就是push完后adb reboot

查找应用进程号,并杀掉该进程

adb root
adb shell
bengal:/ $ ps -A |grep settings
system         4328    494 0 06:27:48 ?     00:00:13 com.android.settings
shell          9269   9266 1 09:40:52 pts/27 00:00:00 grep settings
bengal:/ $ kill 4328
12、adb shell dumpsys使用
查看系统服务信息
方法:
adb shell dumpsys -l
或者
adb shell service list

详细说明
注:
adb shell dumpsys servicename -h

代表此模块可以查哪些信息

举例说明,adb shell service list | findstr activity
进入adb shell后,可以使用grep

adb shell dumpsys activity activities----------查看Activity组件信息

adb shell dumpsys activity services-----------查看Service组件信息

adb shell dumpsys activity providers----------产看ContentProvider组件信息

adb shell dumpsys activity broadcasts--------查看BraodcastReceiver信息

adb shell dumpsys activity intents--------------查看Intent信息

adb shell dumpsys activity processes---------查看进程信息


  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值