首页 > 解决方案 > 如何以编程方式将 .apk 安装到 android 设备中?

问题描述

任何人都可以帮助如何以编程方式在 android 设备/模拟器中安装 .apk 文件吗?

我尝试了以下方法:

UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.executeShellCommand("adb shell pm install -t -r /data/local/tmp/com.example.xxxxx.xxxxxx"); 

但它不起作用。

我正在使用 UIAutomator 进行 android 本机应用程序自动化测试,在继续执行测试脚本之前,我需要将 .apk 文件安装到 android 设备/模拟器中。

标签: androidinstallationandroid-uiautomator

解决方案


executeShellCommand在您的设备内运行。不需要adb shell了。

UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.executeShellCommand("pm install -t -r /data/local/tmp/com.example.xxxxx.xxxxxx");

推荐阅读