每天一个安卓测试开发小知识之 (四) ---常用的adb shell命令第二期 pm命令

上一期我们简单介绍了如何进入\退出 adb shell以及 adb shell 的常用命令,本期继续介绍

pm命令

pm是什么,pm -> packageManager 翻译过来就是包管理 ,该命令就是提供包的管理功能

包是什么,在安卓系统中 一个包就是一个app,例如三方包,微信 qq等,手机自带的包,时钟、设置 都是一个个独立的包

1. 查看帮助

adb shell pm -h

2. 查看已安装的全部包

adb shell pm list packages 会列出包名。

包名就是包的唯一id,例如微信的包名就是 com.tencent.mm ,一个手机中包名不能重复,即不能安装包名相同的app

3. 包的安装

adb shell pm install *** 安装apk,** 是手机中的apk路径

例如安装 app-debug.apk (安卓系统中app的后缀名是 .apk

1. push 主机上的apk到手机中

2. 通过 pm install安装



还有一种方式是 直接 adb install app-debug.apk,也能实现相同的功能



无论是 adb install 还是 adb shell pm install 都可以加很多参数,不同的参数又不同的含义

  install [-rtfdg] [-i PACKAGE] [--user USER_ID|all|current]
[-p INHERIT_PACKAGE] [--install-location 0/1/2]
[--install-reason 0/1/2/3/4] [--originating-uri URI]
[--referrer URI] [--abi ABI_NAME] [--force-sdk]
[--preload] [--instant] [--full] [--dont-kill]
[--enable-rollback [0/1/2]]
[--force-uuid internal|UUID] [--pkg PACKAGE] [-S BYTES]
[--apex] [--non-staged] [--force-non-staged]
[--staged-ready-timeout TIMEOUT] [--ignore-dexopt-profile]
[--dexopt-compiler-filter FILTER]
[PATH [SPLIT...]|-]
Install an application. Must provide the apk data to install, either as
file path(s) or '-' to read from stdin. Options are:
-R: disallow replacement of existing application
-t: allow test packages
-i: specify package name of installer owning the app
-f: install application on internal flash
-d: allow version code downgrade (debuggable packages only)
-p: partial application install (new split on top of existing pkg)
-g: grant all runtime permissions
-S: size in bytes of package, required for stdin
--user: install under the given user.
--dont-kill: installing a new feature split, don't kill running app
--restrict-permissions: don't whitelist restricted permissions at install
--originating-uri: set URI where app was downloaded from
--referrer: set URI that instigated the install of the app
--pkg: specify expected package name of app being installed
--abi: override the default ABI of the platform
--instant: cause the app to be installed as an ephemeral install app
--full: cause the app to be installed as a non-ephemeral full app
--enable-rollback: enable rollbacks for the upgrade.
0=restore (default), 1=wipe, 2=retain
--rollback-impact-level: set device impact required for rollback.
0=low (default), 1=high, 2=manual only
--install-location: force the install location:
0=auto, 1=internal only, 2=prefer external
--install-reason: indicates why the app is being installed:
0=unknown, 1=admin policy, 2=device restore,
3=device setup, 4=user request
--update-ownership: request the update ownership enforcement
--force-uuid: force install on to disk volume with given UUID
--apex: install an .apex file, not an .apk
--non-staged: explicitly set this installation to be non-staged.
This flag is only useful for APEX installs that are implicitly
assumed to be staged.
--force-non-staged: force the installation to run under a non-staged
session, which may complete without requiring a reboot. This will
force a rebootless update even for APEXes that don't support it
--staged-ready-timeout: By default, staged sessions wait 60000
milliseconds for pre-reboot verification to complete when
performing staged install. This flag is used to alter the waiting
time. You can skip the waiting time by specifying a TIMEOUT of '0'
--ignore-dexopt-profile: if set, all profiles are ignored by dexopt
during the installation, including the profile in the DM file and
the profile embedded in the APK file. If an invalid profile is
provided during installation, no warning will be reported by `adb
install`.
This option does not affect later dexopt operations (e.g.,
background dexopt and manual `pm compile` invocations).
--dexopt-compiler-filter: the target compiler filter for dexopt during
the installation. The filter actually used may be different.
Valid values: one of the values documented in
https://source.android.com/docs/core/runtime/configure#compiler_filters
or 'skip'
--disable-auto-install-dependencies: if set, any missing shared
library dependencies will not be auto-installed

-R 允许重复安装

-t 允许安装测试包

-d 允许降级安装

-g 安装时直接授予app全部运行时权限

等等参数,这里只介绍一些常用的参数

例如 :

4. 包的卸载

adb shell pm uninstall packageName 或者 adb uninstall packageName packageName 是包名

4.1 包名如何获取

如果是自己开发的app,包名肯定已知,如果是其他的app呢

方式一:通过手机上的界面去查看包名

方式二:通过aapt命令查看 适用于在主机上查看apk的信息

方式三: 通过adb命令查看 适用于手机上查看apk信息

  • 方式一,以小米手机为例,长按app图表 - > 点击感叹号 -> 点击右上角三个点->点击应用详情

  • 方式二: 通过aapt

aapt 是一个安卓提供的一个工具,aapt2下载链接 aapt2简介 可以用来获取apk的详细信息

以linux为例 直接在aapt的目录中运行 ./aapt2 则会看到aapt命令的帮助信息

  • 查看apk信息 ./aapt dump badging ~/app-debug.apk~/app-debug.apk apk的保存路径



    可以看到 包名是 com.miui.sysopt 当前的版本号 569 以及 sdk版本声明的权限等等
  • 方式三 通过adb命令查看包名

当我们打开某个app时,以设置为例,我们可以通过adb命令获取当前界面上是哪个app,从而得到app的包名

对应的adb命令是 adb shell dumpsys activity activities | grep mFocusedApp=ActivityRecord



通过以上命令可以得到当前的app是 com.android.settings 并且可以看到当前的 activity是 com.android.settings/.MainSettings

本期的分享先到这里,每天进步一点点!!!

每天一个安卓测试开发小知识之 (四) ---常用的adb shell命令第二期 pm命令的更多相关文章

  1. React Native环境配置、初始化项目、打包安装到手机,以及开发小知识

    1.前言 环境:Win10 + Android 已经在Windows电脑上安装好 Node(v14+).Git.Yarn. JDK(v11) javac -version javac 11.0.15. ...

  2. IM开发基础知识补课(四):正确理解HTTP短连接中的Cookie、Session和Token

    本文引用了简书作者“骑小猪看流星”技术文章“Cookie.Session.Token那点事儿”的部分内容,感谢原作者. 1.前言 众所周之,IM是个典型的快速数据流交换系统,当今主流IM系统(尤其移动 ...

  3. java 测试开发基础知识(类加载,JVM等)

    写在开头: 面试的时候别人很可能会问你的java原理,.class load 原理, jvm机制,这些都是Java的底层知识,特整理如下: 1. 首先,编写一个java程序,大家会用ide编写一个例如 ...

  4. bootstrap学习笔记(网页开发小知识)

    这是我在学习Boostrap网页开发时遇到的主要知识点: 1.导航条navbar 添加.navbar-fixed-top类可以让导航条固定在顶部,固定的导航条会遮住页面上的其他内容,除非给<bo ...

  5. Python接口开发小知识

    关于数据库设计 接口开发多学习数据库表操作,这是要点 不存在删除数据,每个可能被删除数据的表加一个is_active属性 不同的表可以有多个相同的字段,字段属性少用禁止非空 不要设置太多主外键(高内聚 ...

  6. 【ZeyFraのJavaEE开发小知识05】Mybatis-Plus & Axios

    关于如何在Mybatis-Plus中添加SQL拦截器 之前ZeyFra在MyBatis-Plus[踩坑记录01]一文中提到过,使用Mybatis-Plus时最好使用MybatisSqlSessionF ...

  7. JSP+Ajax站点开发小知识

    一.JSP基础 1.<select  name="love"  size="3">当中的size属性指定了列表框显示选项的条数.假设全部选项多于这个 ...

  8. 安卓(Android)开发基础知识

    .aar文件 .aar是一种压缩文件,和.jar类似,不过它可以包含资源文件,例如图片.drawable.xml资源 .jar文件 在软件领域,JAR文件(Java归档,英语:Java ARchive ...

  9. 一个Monkey测试的小坑

    环境:Genymotion模拟器+Custome Phone-6.0.0,API 23 操作步骤如下: cd data/app ls //为了获取待测apk的包名 获取结果如下: 执行命令,其中包名使 ...

  10. web开发小知识

    session共享机制:f5刷新是再次提交之前的数据请求 地址栏回车属于不同的请求 不同浏览器获取不到之前数据 同一浏览器可以获取同步数据 session注销:session.invalidate() ...

随机推荐

  1. ET框架运行(Mac环境)--客户端

    1:环境 Mac电脑,安装.net cor2 2.2 ,JetBrains Rider编辑器,Unity环境(2018.4.28f1) 终端运行:  dotnet --version  查看是否安装n ...

  2. C#.Net筑基-泛型T & 协变逆变

    01.什么是泛型? 泛型(Generics)是C#中的一种强大的强类型扩展机制,在申明时用"占位符"类型参数"T"定义一个"模板类型",比较 ...

  3. .NET程序员的多语言笔记本:Polyglot Notebook

    大家好,我是Edison. 之前在学习机器学习的时候,使用了Jupyter Notebook这个笔记本工具,我就在想.NET这边有没有类似的,今天就跟你介绍下Polyglot Notebook这个工具 ...

  4. iOS开发UI篇—自定义瀑布流控件(接口设计)

    iOS开发UI篇-自定义瀑布流控件(接口设计) 一.简单说明 1.关于瀑布流 电商应用要展示商品信息通常是通过瀑布流的方式,因为每个商品的展示图片,长度和商都都不太一样. 如果不用瀑布流的话,展示这样 ...

  5. windows 服务器关于ftp服务的搭建

    简介 服务器下载 ftpZilla server 安装 笔记本电脑下载 ftpZilla client 服务器防火墙开启21端口的进出站 https://jingyan.baidu.com/artic ...

  6. iPaaS架构深入探讨

    在数字化时代全面来临之际,企业正面临着前所未有的挑战与机遇.技术的迅猛发展与数字化转型正在彻底颠覆各行各业的格局,不断推动着企业迈向新的前程.然而,这一数字化时代亦衍生出一系列复杂而深奥的难题:各异系 ...

  7. Organization-Administration-Business-Operational Guidelines: "达达(京东)秒送"众包快递 + "货拉拉"平台的"司机师傅"的"岗前培训" 及 "行为守则"

    达达(京东)秒送: 众包快递 图0 图1 图2 图3 图4 图5 图6 图7 图8 图9 图10 图11 图12 图13 图14 图15 图16 图17 更多 图1 图2 图3 图4 图5 图6 图7 ...

  8. SciTech-Mathmatics-Probability+Statistics-I-Statistics:Quantifing Uncertainty + Population:Parameters and Sample:Statistics 总体和样本

    https://zhuanlan.zhihu.com/p/674010971?utm_id=0 I Population and Sample 总体和样本 统计学提供了一种量化不确定性的方法,使我们能 ...

  9. 高阶篇:1.4)TRIZ创新算法

    本章目的:掌握最基础的ARIZ-71的矛盾矩阵的运用 1.TRIZ概论 Triz,发明问题解决理论的拉丁文翻译的首字母缩写,由苏联发明家根里奇*阿奇舒勒于1946年开始,每年动用1500人的人力,在研 ...

  10. 安卓APP导出

    直接从项目中运行生成的 app-debug.apk 是用一个临时的调试密钥签名的,很多手机会因为安全策略而拒绝安装,或者在安装时给出更强的安全警告. 为什么需要签名? 给App签名主要有三个目的: 身 ...