5

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.

7
  • Check this link. it may help stackoverflow.com/questions/13571145/android-adb-not-found Commented Aug 18, 2015 at 12:14
  • Thanks for your reply.I tried all those related commands,but no luck. Commented Aug 19, 2015 at 5:45
  • @DurgaPrasad Did you get the solution for this issue? I am also facing same issue. Commented Mar 5, 2016 at 10:50
  • This is most likely caused by local environment, which is why it works on terminal. I fixed the problem by setting global environment stackoverflow.com/a/30912162. Restart your mac afterwards and see how it goes. Commented Jun 21, 2016 at 11:39
  • @HendraAnggrian I do have global env setup but Eclipse Neon 4.6.0 still keeps on giving this error. I've explicitly set ANDROID_HOME as well under Run Configuration Commented Dec 21, 2016 at 20:25

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

-3

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.