Android adb 安装apk程序


前言

多数情况下,用户都是从应用商店或某网页下载apk后从手机上直接安装apk文件,在调试或下载到电脑上时候,我们就可以直接通过adb安装到手机。在测试小伙伴测试过程中也可能直接收到开发小伙伴直接发来的apk,有些小伙伴通过电脑微信或qq传递手机微信或手机qq后安装,此外也可以通过adb 直接安装。

Android adb 启动APP
Android代码安装apk程序

ADB简单介绍

adb 是Android 开发调试工具,在…\Android\Sdk\platform-tools目录中
在这里插入图片描述
单独下载sdk解压或安装就可以得到,我们在环境变量中添加…\Android\Sdk\platform-tools后,在命令行窗口就可以使用 adb 命令了。没添加环境变量需要把整个路径带上。

安装命令

adb install -r app.apk
覆盖安装的话最好都带上-r,不是覆盖可以不用带-r

操作:

  1. win + r 或直接打开运行,输入cmd
    在这里插入图片描述
  2. 输入adb install 然后将apk文件拖入命令行窗口,回车
    在这里插入图片描述
  3. 安装成功
    在这里插入图片描述

安装失败情况

  1. 签名不一致,由于debug和release使用的签名不一致,这种情况下,可以先卸载已安装的版本,可手动卸载或 adb 卸载adb uninstall 包名
    在这里插入图片描述
  2. 有些手机需要在安装过程在手机上确认安装(小米系列)
  3. 开启调试模式
    设置-系统-开放人员选项-开启开放人员选项和usb调试
    在这里插入图片描述
    在这里插入图片描述

adb 安装测试包

-t ,详细如下:

adb install -t app-debug.apk

Android studio 3.0后 ,编译debug版本时,默认在manifest的application里面加入android:testOnly="true"属性。因此真机上手动安装是失败的,adb install app-debug.apk也是失败的。要使用 adb install -t app-debug.apk
另外的解决办法:在项目中的全局配置gradle.properties文件中设置:android.injected.testOnly=false,这样就避免debug版本手动安装失败的问题,这种主要是解决某些场景的测试需要。

adb 安装卸载的所有命令摘要

install [-lrtsdg] [--instant] PACKAGE
     push a single package to the device and install it
 install-multiple [-lrtsdpg] [--instant] PACKAGE...
     push multiple APKs to the device for a single package and install them
 install-multi-package [-lrtsdpg] [--instant] PACKAGE...
     push one or more packages to the device and install them atomically
     -r: replace existing application
     -t: allow test packages
     -d: allow version code downgrade (debuggable packages only)
     -p: partial application install (install-multiple only)
     -g: grant all runtime permissions
     --abi ABI: override platform\'s default ABI
     --instant: cause the app to be installed as an ephemeral install app
     --no-streaming: always push APK to device and invoke Package Manager as separate steps
     --streaming: force streaming APK directly into Package Manager
     --fastdeploy: use fast deploy
     --no-fastdeploy: prevent use of fast deploy
     --force-agent: force update of deployment agent when using fast deploy
     --date-check-agent: update deployment agent when local version is newer and using fast deploy
     --version-check-agent: update deployment agent when local version has different version code and using fast deploy
     (See also `adb shell pm help` for more options.)
 uninstall [-k] PACKAGE
     remove this app package from the device
     '-k': keep the data and cache directories

猜你喜欢

转载自blog.csdn.net/lanlangaogao/article/details/125298583