adb命令使用

yangChong 2020-07-29

相关命令

查看当前连接设备

1 adb devices

如果发现多个设备

1 adb -s 设备号 其他指令

安装命令

1 adb install path\name.apk

覆盖安装

1 adb install path\name.apk

卸载apk包

1.查看apk主包名

知道apk包名,反编译操作

D:\>aapt dump badging jisuanqi_587.apk
package: name=‘com.ibox.calculators‘ versionCode=‘587‘ versionName=‘2.8.7‘ platformBuildVersionName=‘6.0-2704002‘
sdkVersion:‘14‘
targetSdkVersion:‘19‘

不知道apk报名,打开模拟器中的app

1 D:\>adb shell dumpsys window | findstr mCurrentFocus
2   mCurrentFocus=Window{e66be70 u0 com.ibox.calculators/com.ibox.calculators.CalculatorActivity}

2.卸载操作

1 D:\>adb uninstall com.ibox.calculators
2 Success

 进入手机的超级终端

1 D:\>adb shell
2 vbox86p:/ #

向模拟器中写入文件(上传文件)

   首先需要知道俩个,1.windos下文件的路径及文件名称,2.上传至手机模拟器上的路径

1 adb shell find / -name 文件夹名称 -type d

开始上传

1 D:\>adb push file_test.txt /data/media/0/Download
2 file_test.txt: 1 file pushed, 0 skipped. 0.0 MB/s (13 bytes in 0.002s)

注: file_test.txt 为当前D:\下的文档,/data/media/0/Download 为手机路径

从模拟器中复制文件(下载文件)

1 D:\>adb pull /data/media/0/Download/test/file_test.txt File
2 /data/media/0/Download/test/file_test.txt: 1 file pulled, 0 skipped. 0.0 MB/s (13 bytes in 0.001s)

注: /data/media/0/Download/test/file_test.txt   为手机路径,  File 为电脑路径

查看app相关信息,包括action,codepath,version等等

1 adb shell dumpsys package com.ibox.calculators

查看app的路径

1 C:\Users\Alin>adb shell pm path com.ibox.calculators
2 package:/data/app/com.ibox.calculators-JFzmL_qeOWqldw_nuBAG2A==/base.apk

启动app

先根据adb shell dumpsys window | findstr mCurrentFocus查找到<package_name>/.<activity_class_name>,在使用adb shell am start -n <package_name>/.<activity_class_name>

C:\Users\Alin>adb shell am start -n com.ibox.calculators/com.ibox.calculators.CalculatorActivity
Starting: Intent { cmp=com.ibox.calculators/.CalculatorActivity }

删除与包相关的所有数据,清楚数据和缓存

1 C:\Users\Alin>adb shell pm clear com.ibox.calculators
2 Success

查看某个app的进程相关信息

C:\Users\Alin>adb shell ps|findstr com.ibox.calculators
u0_a102       3988   282  984300 106688 ep_poll      f15f4bb9 S com.ibox.calculators:ghosty
u0_a102       4020   282  998936 107988 ep_poll      f15f4bb9 S com.ibox.calculators:pushservice
u0_a102       4030     1  985296  22240 unix_stream_read_generic f15f4bb9 S com.ibox.calculators:ghosty
u0_a102       4059   282 1171828 215852 ep_poll      f15f4bb9 S com.ibox.calculators

杀掉某个进程,一般用于模拟某个bug复现

1 C:\Users\Alin>adb shell kill 5213

查看某一个app的内存占用

1 C:\Users\Alin>adb shell dumpsys meminfo com.ibox.calculators

利用adb命令按住案件

1 adb shell input keyevent KEYCODE_BACK

相关命令可查看这个博客:https://www.cnblogs.com/bluestorm/p/4886662.html

查看日志命令

adb logcat [选项] [过滤项] (选项过滤项可填可不填)

-s:设置输出日志的标签, 只显示该标签的日志;

C:\Users\Alin>adb logcat -s PackageManager
--------- beginning of main
--------- beginning of system
07-28 10:26:00.282  1091  1481 W PackageManager: Failure retrieving resources for com.ibox.calculators

-f:将日志输出到文件,该文件是在手机上的路径+文件名

1 C:\Users\Alin>adb logcat -f /data/media/0/Download/test.log

-c:清空所有日志的缓存信息

1 C:\Users\Alin>adb logcat -c
-v:
  • adb logcat -v time :可以查看日志的输出时间;
  • adb logcat -v threadtime :可以查看日志的输出时间和线程信息;
  • adb logcat -v process:格式为“优先级 (进程ID) : 日志信息 "的日志;
  • adb logcat -v tag:格式为 " 优先级 / 标签 : 日志信息" 的日志;
  • adb logcat -v thread :格式为 "优先级 ( 进程ID : 线程ID) 标签 : 日志内容" 的日志;
  • adb logcat -v raw :只输出日志信息, 不附加任何其他信息; adb logcat -v long:格式为 “ [ 日期 时间 进程ID : 线程ID 优先级 / 标签] 日志信息 ” 的日志。
过滤项解析
V : Verbose (明细);
D : Debug (调试);
I: Info (信息); 
W: Warn (警告);
E: Error (错误);
F: Fatal (严重错误);
S : Silent(Super all output) (最高的优先级, 可能不会记载东西)
举例:1、显示 Error 以上级别的日志:adb logcat *:E 
1 C:\Users\Alin>adb logcat *:W
C:\Users\Alin>adb logcat -s System:E
--------- beginning of main
--------- beginning of system
07-28 10:37:40.043  6232  6410 E System  :  ******** DEPRECATED FUNCTIONALITY ********
07-28 10:37:40.043  6232  6410 E System  :  * The implementation of the KeyFactory.RSA algorithm from
07-28 10:37:40.043  6232  6410 E System  :  * the BC provider is deprecated in this version of Android.
07-28 10:37:40.043  6232  6410 E System  :  * It will be removed in a future version of Android and your
07-28 10:37:40.043  6232  6410 E System  :  * application will no longer be able to request it.  Please see
07-28 10:37:40.043  6232  6410 E System  :  * https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html
07-28 10:37:40.043  6232  6410 E System  :  * for more details.
07-28 10:39:22.948  6232  6427 E System  :  ******** DEPRECATED FUNCTIONALITY ********
07-28 10:39:22.948  6232  6427 E System  :  * The implementation of the KeyFactory.RSA algorithm from
07-28 10:39:22.948  6232  6427 E System  :  * the BC provider is deprecated in this version of Android.
07-28 10:39:22.948  6232  6427 E System  :  * It will be removed in a future version of Android and your
07-28 10:39:22.948  6232  6427 E System  :  * application will no longer be able to request it.  Please see
07-28 10:39:22.948  6232  6427 E System  :  * https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html
07-28 10:39:22.948  6232  6427 E System  :  * for more details.
 
 

相关推荐