命令相关

ADB命令

常用 ADB 命令

导入文件到手机

adb push local remote

e.g

adb push D:\Desktop\安装包\保意\20200302正式线替换图标\laiDianYi-release.apk sdcard

导出手机文件

adb pull remote local

导出bug日志(anr也可以查看)

//1. 生成bug日志
adb bugreport
//2. cd到d盘下。拉取上一步生成的bugreport
adb pull /data/user_de/0/com.android.shell
  1. 找到d:/com.android.shell/files/bugreports,解压zip文件,其中anr日志在zip内的FS/data/anr内

列出设备(验证手机是否连上adb)

adb devices

查看安卓包名

法一:adb shell am monitor

然后启动需要获取包名的应用

法二:adb shell pm list packages -3

查看自己安装的 app 包名

法三:安卓系统中:设置–应用–正在运行 查看

法四:安卓系统:文件管理器访问目录/data/data 下,文件夹即为包名

法五:将 apk 反编译,查看 AndroidManifest.xml 中的 package

安装apk

adb -s 真机序列号 install **.apk

adb -s 127.0.0.1:6555 install -r **.apk

其中 -s SD卡;-r 重装

如果只有一台真机,那么直接adb -s install **.apk

卸载apk

adb uninstall 包名

重启设备

adb -s 真机序列号 reboot

查看文件

adb -s 真机序列号 shell
cd到文件目录下
ls

ADB 命令截屏

截屏 screencap

adb shell screencap 文件保存路径

ADB 命令录像

录像 screenrecord

adb shell screenrecord 文件保存路径

Control + C 停止屏幕录制,否则,到三分钟或 --time-limit 设置的时间限制时,录制将自动停止。

screenrecord 部分参数

选项说明
–size width x height设置分辨率 eg:1280x720
–bit-rate rate视频比特率,默认值为 4Mbps,可以设6Mbps,这样质量更好 eg:adb shell screenrecord --bit-rate 6000000 /sdcard/demo.mp4
–time-limit time设置最大录制时长(以秒为单位)。默认值和最大值均为 180(3 分钟)。

调用ActivityManager(am 命令)

发送 intent

adb shell am start -a android.intent.action.VIEW

启动Activity

adb shell am start -n 包名/类名

e.g:

adb shell dumpsys activity|findstr Run
找到正在运行的某个activity(com.tencent.mobileqq/.activity.SplashActivity)
adb shell am start -n com.tencent.mobileqq/.activity.SplashActivity

启动service

adb shell am startservice 包名/类名

e.g:

adb shell am startservice -n com.programandroid/.Service.BindServiceMethod

发送广播

adb shell am broadcast -a 广播Action

e.g:

adb shell am broadcast -a "android.intent.action.BOOT_COMPLETED"

强行停止应用

adb shell force-stop 包名

e.g:

adb shell dumpsys activity|findstr Run
找到某个正在运行的activity(com.tencent.mobileqq/.activity.LoginActivity)
查看正在运行的应用情况 adb shell ps|findstr mobileqq

adb shell am force-stop com.tencent.mobileqq

再次查看这个正在运行的应用情况 adb shell ps|findstr mobileqq
adb shell dumpsys activity|findstr Run

使用adb 命令进入recovery 模式

进入Recovery 模式可以使用组合键,也可以使用adb 命令 adb 命令进入recovery 模式如下

adb reboot recovery

跳过Google 开机向导的命令

adb shell pm disable com.google.android.setupwizard
adb shell settings put global device_provisioned 1
adb shell settings put secure user_setup_complete 1

启动开机向导命令

C:\Users\Administrator>adb shell am start  com.google.android.setupwizard/.user.WelcomeActivity
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.android.setupwizard/.user.WelcomeActivity }

C:\Users\Administrator>

调用 PackageManager(pm 命令)

卸载apk

adb shell pm uninstall 包名

查看手机中所有apk 包名

adb shell pm list packages

查看已知权限组

adb shell pm list permission-groups

查看手机Feature 支持

adb shell pm list features

根据包名,查看apk 安装路径

adb shell pm path 包名

清除app 数据

adb shell pm clear 包名

多用户相关

查看支持最多用户数 adb shell pm get-max-users

查询系统所有用户 adb shell pm list users

创建新用户 adb shell pm create-user user_name

移除指定id用户 adb shell pm remove-user user_id

dumpsys将系统数据转储到屏幕

获取当前运行的Activity

adb shell dumpsys activity | findstr Run

获取当前指定包名的Activity栈

adb shell "dumpsys activity|grep" 包名

’grep‘不是内部或外部命令,也不是可运行的程序 或批处理文件。所以加双引号

获取apk 版本号,权限等信息的方法

adb shell dumpsys package com.xxx.xxx(包名)

查看手机系统进程

使用Top命令查看系统进程

adb shell top

使用 ps 命令查看系统进程

adb shell ps

结合findstr 命令 过滤多余的信息

adb shell ps | findstr qq

使用logcat抓 log信息

在cmd窗口输出logcat信息

adb logcat

把logcat输出到文件中

adb logcat > D:\1.txt

例子:

#adb  logcat -d -b system -v time >本地文件.txt

adb  logcat -d -b system -v time >C:\Users\Administrator\Desktop\temp\悦以国际\logcat.txt
adb  logcat -d -b system -v time >C:\Users\Administrator\Desktop\temp\星球秀场\logcat.txt
adb  logcat -d -b system -v time >C:\Users\Administrator\Desktop\temp\SBC2.0\logcat.txt

使用 -s 过滤log标签

adb logcat -s 关注log标签

e.g

adb logcat -s AndroidRuntime

使用 -c 清除缓存log

adb logcat -c

电量管理相关命令

模拟拔下设备电源

adb shell dumpsys battery unplug

低电量条件下的行为

adb shell settings put global low_power 1

恢复电源修改

adb shell dumpsys battery reset

keytool 相关

查看apk的签名

首先用解压软件解压出META-INF目录下的CERT.RSA文件

keytool -printcert -file D:\Desktop\CERT.RSA

查看keystore的签名

keytool -list -keystore D:\Desktop\app_key

查看keystore的签名

keytool -list -v -keystore e:\debug.keystore -storepass xxx(密匙)

 

 

查看AS自带签名文件

Android Studio自带签名文件路径:(密码:android)

C:\Users\Administrator\.android\debug.keystore

keytool -list -v -keystore C:\Users\Administrator\.android\debug.keystore

MonkeyRunner

执行键盘录制

  1. monkeyrunner.bat设置到环境变量中:把D:\Android\SDK\tools\bin添加到环境变量中;同时更改环境变量为jdk8

  2. 脚本

    record.py

    #!/usr/bin/env monkeyrunner
    # Copyright 2010, The Android Open Source Project#
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at#
    # http://www.apache.org/licenses/LICENSE-2.0#
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    from com.android.monkeyrunner import MonkeyRunner as mr
    from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
    device = mr.waitForConnection()
    recorder.start(device)
    

    playback.py

    #!/usr/bin/env monkeyrunner  
    # Copyright 2010, The Android Open Source Project  
    #  
    # Licensed under the Apache License, Version 2.0 (the "License");  
    # you may not use this file except in compliance with the License.  
    # You may obtain a copy of the License at  
    #  
    # http://www.apache.org/licenses/LICENSE-2.0  
    #  
    # Unless required by applicable law or agreed to in writing, software  
    # distributed under the License is distributed on an "AS IS" BASIS,  
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
    # See the License for the specific language governing permissions and  
    # limitations under the License.   
    import sys  
    from com.android.monkeyrunner import MonkeyRunner   
    # The format of the file we are parsing is very carfeully constructed.  
    # Each line corresponds to a single command. The line is split into 2  
    # parts with a | character. Text to the left of the pipe denotes  
    # which command to run. The text to the right of the pipe is a python  
    # dictionary (it can be evaled into existence) that specifies the  
    # arguments for the command. In most cases, this directly maps to the  
    # keyword argument dictionary that could be passed to the underlying  
    # command.   
    # Lookup table to map command strings to functions that implement that  
    # command.  
    CMD_MAP = {  
        'TOUCH': lambda dev, arg: dev.touch(**arg),  
        'DRAG': lambda dev, arg: dev.drag(**arg),  
        'PRESS': lambda dev, arg: dev.press(**arg),  
        'TYPE': lambda dev, arg: dev.type(**arg),  
        'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)  
        }  
    # Process a single file for the specified device.  
    def process_file(fp, device):  
        for line in fp:  
            (cmd, rest) = line.split('|')  
            try:  
                # Parse the pydict  
                rest = eval(rest)  
            except:  
                print 'unable to parse options'  
                continue   
            if cmd not in CMD_MAP:  
                print 'unknown command: ' + cmd  
                continue   
            CMD_MAP[cmd](device, rest)  
    def main():  
        file = sys.argv[1]  
        fp = open(file, 'r')   
        device = MonkeyRunner.waitForConnection()     
        process_file(fp, device)  
        fp.close();     
    if __name__ == '__main__':  
        main()
    
  3. 执行录制脚本

    monkeyrunner d:\replay\record.py
    

    wait: 用来插入下一次操作的时间间隔,点击后即可设置时间,单位是秒

    Press a Button:用来确定需要点击的按钮,包括menu、home、search,以及对按钮的press、down、up属性

    Type Something:用来输入内容到输入框

    Fling:用来进行拖动操作,可以向上、下、左、右,以及操作的范围

    Export Actions:用来导出脚本,不需要后缀名,也可以添加后缀名

    Refresh Display:用来刷新手机界面,估计只有在断开手机后,重新连接时才会用到

    点击“export actions”保存录制脚本到 d:\replay\r

  4. 执行回放脚本

    monkeyrunner d:\replay\playback.py d:\replay\r
    

    其中r是上面录制的脚本文件

如果录制脚本的时候报SWT folder '..\framework\x86_64' does not exist.错误:

那么打开monkeyrunner.bat更改:

.set frameworkdir=lib (纠正)==》set frameworkdir=..\lib 

.Dcom.android.monkeyrunner.bindir=..\framework -jar %jarpath% %* (纠正)==》Dcom.android.monkeyrunner.bindir=..\..\platform-tools -jar %jarpath% %*

问题

adb 识别不出的问题

问题:

adb devices
adb server is out of date

方法一:

  1. 关闭eclipse

  2. cmd-->adb nodaemon server找出adb端口(软件默认5037)

    cmd-->netstat -ano|findstr 5037列出所有端口为5037的记录。找到本地的记录的pid

  3. 任务管理器中:结束掉该pid的进程,关闭adb.exe

  4. 重启eclipse

or 命令行关闭占用端口的进程

  1. 找出adb端口(软件默认5037)
    adb nodaemon server

  2. 列出所有端口为5037的记录。找到本地的记录的pid
    netstat -ano|findstr 5037

  3. 结束进程
    taskkill -f -im pid

方法二:

  1. 停止ADB服务

    ./adb kill-server

  2. 开启ADB 服务

    ./adb start-server

方法三:

  1. 插拔USB重试

  2. 手机关机重启

  3. 插上USB后,重新装一下驱动,ADB驱动

  4. 关掉电脑上360手机助手,安全卫士之类的

  5. windows进程下关掉adb.exe; 关掉eclipse重试

  6. 输入命令:

adb kill-service

adb start-server

adb root adb devices
  1. 找到.android文件夹,在该文件夹下添加一个adb_usb.ini文件(若已存在,则直接打开修改),里面内容为0xVID号

    VID号获取方法:

    计算机管理 -〉设备管理 -〉android phone -> Android Composite ADB Interface ->右键属性-〉详细信息 -〉找到VID_后面的四位数字即可

设备android 5以下不能识别到的问题

  • 查看开发者是否开启USB调试
  • 查看是否选择了传输方式(不会主动弹出,需要去设置里找)

adb devices设备名称相同的问题

解决:

  1. 只留下一个设备

  2. adb shell

  3. echo 123321234 >/sys/class/android_usb/android0/iSerial

  4. exit 推出shell模式

  5. adb kill-server

  6. adb start-server

  7. adb devices

问题:adb server is out of date

解决:

  1. 关闭eclipse
  2. cmd–>adb nodaemon server照出adb端口(软件默认5037)
  3. cmd–>netstat -ano|findstr 5037列出所有端口为5037的记录。找到本地的记录的pid
  4. 任务管理器中:结束掉该pid的进程,关闭adb.exe
  5. 重启eclipse

Android Studio运行后选用了AS自带的签名文件

检查AS的Build Variants对应渠道的Active Build Variant(如果两个不同版本打开同一份代码会导致这个变量变掉)

改成对应渠道就是正常的签名文件了(与AS右侧Gradle--ZCZG4.0--daogou--Tasks--build--assembeZcZg打出来的包是一样的)

 

AS点选项打包和直接运行的签名区别.png

grep不是内部或外部命令,也不是可运行的程序 或批处理文件。

所以给命令加双引号

如:

//获取指定包名当前的activity栈
adb shell "dumpsys activity|grep" 包名
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值