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.

Nitesh
  • 177
  • 7
Durga Prasad
  • 301
  • 1
  • 2
  • 8
  • Check this link. it may help http://stackoverflow.com/questions/13571145/android-adb-not-found – saravana Aug 18 '15 at 12:14
  • Thanks for your reply.I tried all those related commands,but no luck. – Durga Prasad Aug 19 '15 at 05:45
  • @DurgaPrasad Did you get the solution for this issue? I am also facing same issue. – user11016 Mar 05 '16 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 http://stackoverflow.com/a/30912162. Restart your mac afterwards and see how it goes. – Hendra Anggrian Jun 21 '16 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 – vikramvi Dec 21 '16 at 20:25
  • @DurgaPrasad did you find solution for this, kindly share here. – vikramvi Dec 21 '16 at 20:41
  • https://bugs.eclipse.org/bugs/show_bug.cgi?id=509628 , filed ticket today. – vikramvi Dec 22 '16 at 09:25

3 Answers3

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

V'94
  • 31
  • 3
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.

prakash krishnan
  • 801
  • 6
  • 10
-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();
Monal
  • 1