简体   繁体   中英

Cannot run program "adb": error=2, No such file or directory while executing through eclipse

I am trying to automate android devices using appium in Mac machine(Yosemite OS).

I downloaded and set all the required PATHS like sdk,build-tools,tools,paltform-tools,platforms and able to run the adb commands through terminal sucessfully.

But I written sample below java code

**Process p = Runtime.getRuntime().exec("adb devices");** 

Getting output:

Cannot run program "adb": error=2, No such file or directory**

I am unable to figure out the exact problem, why it is working through terminal and why i am getting error through eclipse even I set path for everything.

Could you please any one suggest me what exactly the issue.Please do the needful.

could you please try the following line:

Process p = Runtime.getRuntime().exec(new String[]{"bash", "-l", "-c", "adb devices"});

My answer is based on another link in stackoverflow which resolved my problem and it sounds very similar to yours: https://stackoverflow.com/a/54923150/3439297

I faced this issue with IntelliJ community edition+ Mac combo. But the reason seems the same, try to invoke your IDE (Eclipse) using the command prompt (Via Terminal) so that it can use the system paths, and in turn recognize adb, you mentioned that adb works from terminal so once the IDE launches from terminal again the paths would be honored.

You can use following code on Android: To enable the WIFI:

String ADB=System.getenv("ANDROID_HOME");
String cmd = "/platform-tools/adb shell am broadcast -a io.appium.settings.wifi --es setstatus enable";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(ADB+cmd);
pr.waitFor();

To Disable the WIFI use:

String ADB=System.getenv("ANDROID_HOME");
String cmd = "/platform-tools/adb shell am broadcast -a io.appium.settings.wifi --es setstatus disable";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(ADB+cmd);
pr.waitFor();

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM