[英]Programmatically executing adb install command in java
我正在尝试从Java应用程序将android应用安装到设备中。
使用以下命令-Runtime.getRuntime()。exec(“ adb install /apps/testapp.apk”);
我遇到以下错误-无法运行程序“ adb”:error = 2,没有这样的文件或目录
我是否必须使用ProcessBuilder来开始命令执行?
我认为问题可能是
adb
环境变量。 你可以尝试全路径 使用绝对文件路径,使用-r选项重新安装应用程序(如果已安装):
Runtime.getRuntime().exec("adb install -r _HERE_AbsoluteFilePath_ ");
如果您要等待执行:
String[] commands = new String[3];
commands[0] = "adb";
commands[1] = "install";
commands[2] = "-r";//reinstall if already installed
commands[3] = ___HERE_AbsoluteFilePath___;
Process p1 = Runtime.getRuntime().exec(commands, null);
p1.waitFor();
PS:如果无法在控制台窗口或终端中运行adb,请使用adb的绝对文件路径或包含环境变量的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.