I am trying to install an android app into the device from a Java application.
Using the following command - Runtime.getRuntime().exec("adb install /apps/testapp.apk");
I face the following error - Cannot run program "adb": error=2, No such file or directory
Should I have to use ProcessBuilder to start the command execution?
I think problem may be
adb
environment variable is not set. you can try with full path Use absolute file paths, use -r option to reinstall app if already installed:
Runtime.getRuntime().exec("adb install -r _HERE_AbsoluteFilePath_ ");
If you will be waiting on an execution:
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: if unable to run adb in console window or terminal - use absolute file path for adb or include path to environment variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.