任何人都可以帮助如何以编程方式在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原生app自动化测试,我需要在继续执行测试脚本之前将.apk文件安装到android设备/模拟器中。
executeShellCommand
在你的设备内运行。再也不需要adb shell
了。
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.executeShellCommand("pm install -t -r /data/local/tmp/com.example.xxxxx.xxxxxx");
您可以使用以下代码从命令行安装应用程序
adb install example.apk
Before execute `adb shell pm install`, run "adb root" command firstly.
如果您植入设备,则可以省略此步骤。