'java -version' failed. Error: spawn ENOENT

Unable to launch a android device using appium due to below error. Java -version returns below results when running on command prompt.

java version “1.8.0_45”
Java™ SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot™ 64-Bit Server VM (build 25.45-b02, mixed mode

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: ‘java -version’ failed. Error: spawn ENOENT) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 512 milliseconds

Please help in this regards, it is a blocker for our testing.

Hi @rohit_gupta.

Please try with java version 1.7 and check.


I am hoping you have installed Android SDK properly with required packages.

Did you configured Android environment properly?
If you are not, Add “ANDROID_HOME” system environmental variable pointing to Android SDK path,
ANDROID_HOME — D:\UD\sdk (this is where i copied my Android SDK)

Add following to your system “PATH” variable - %ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;

If you have configured above var.s properly,
In command prompt, what “adb devices” command returns.

Check you have added java home in environment variable

if already set then try below solution

Thanks UD for reply. I don’t see any devices in command prompt. I have all properties configured as you mentioned.On Running adb devices, I don’t see any devices. Please refer attached screenshot.

Thanks Sujata for reply. I tried java 1.7, still no luck :frowning:

Thanks Guneet, It resolved my initial problem. Now I am not seeing any connected device :frowning: I need to find out a way to configure device now. :smile:

Meanwhile If you have any documentation for the same please share. Attaching logs for reference.

info: [debug] Checking whether adb is present

info: [debug] Using adb from C:\Users\Rohit\AppData\Local\Android\sdk\platform-tools\adb.exe
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Checking whether app is actually present
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\Rohit\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 0 device(s) connected
info: [debug] Could not find devices, restarting adb server

@rohit_gupta add your device usb driver

Check you have enabled usb debugging

I’m getting same issue on mac(Yosemite) but if i try “java -version” on terminal it works fine. I have all the environment variable setup as when i run Appium doctor it show all the checks are passed.
Any solution.

Same here… all variables defined OK, still getting:

info: [debug] Error: ‘java -version’ failed. Error: spawn ENOENT

This started after upgrading 1.3.7 to 1.4.0. Will try to downgrade and let you know.

Found a workaround:
Just install Appium on a folder path that contains no spaces (For example: C:\Appium).
Now everything works fine.