Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to start an Appium session, err was: Error: 'java -version' failed. Error: spawn ENOENT [on hold] #4229

Closed
vijay0850 opened this issue Dec 6, 2014 · 51 comments
Assignees

Comments

@vijay0850
Copy link

Hi Im getting these error message on Appium server please help me to resolve it.

Checking if an update is available

Update not available
Starting Node Server
info: Welcome to Appium v1.3.4 (REV c8c79a8)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"18","automationName":"Appium"}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"D:\AndroidApps\test.apk","platformVersion":"4.2.2","platformName":"Android","deviceName":"0123456789ABCDEF","appActivity":".Main","browserName":"","appPackage":"com.test.Main"}}
info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: [debug] Using local app from desired caps: D:\AndroidApps\test.apk
error: Failed to start an Appium session, err was: Error: 'java -version' failed. Error: spawn ENOENT
info: [debug] Creating new appium session abc1d4ab-6f9b-4842-a856-7db52c2f0c0c
info: Starting android appium
info: [debug] Getting Java version
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Error: 'java -version' failed. Error: spawn ENOENT
at C:\Users\elcot\Downloads\Vijay_Important\Appium\node_modules\appium\lib\devices\android\android-common.js:1033:17
at exithandler (child_process.js:633:7)
at ChildProcess.errorhandler (child_process.js:649:5)
at ChildProcess.EventEmitter.emit (events.js:95:17)
at Process.ChildProcess._handle.onexit (child_process.js:795:12)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT)","origValue":"'java -version' failed. Error: spawn ENOENT"},"sessionId":null}
info: <-- POST /wd/hub/session 500 210.506 ms - 208

@triager triager added the Needs Triage bugs which are not yet confirmed label Dec 6, 2014
@paymand
Copy link
Member

paymand commented Dec 8, 2014

I think the error is pretty obvious. Either you don't have Java installed or it is not in the path. You can check that by running java -version in the terminal.

@jlipps jlipps removed the Needs Triage bugs which are not yet confirmed label Dec 8, 2014
@jlipps jlipps closed this as completed Dec 8, 2014
@vijay0850
Copy link
Author

Hi,

I have latest version java 8 update 25 in my PC. Still im getting the error on appium. In appium older version it working fine. Please check with this issue

@vijay0850
Copy link
Author

Im having the following setup things,

Java 8 update 25
Latest Android sdk
Appium 1.3.4.1
Installed Node.Js
Eclipse luna

All the Path are setup perfectly.But Im getting java-version error :(

@paymand
Copy link
Member

paymand commented Dec 9, 2014

Did you try running java -version in your Windows command prompt window?

@vijay0850
Copy link
Author

yes I did please see below screen shot
picture

@paymand
Copy link
Member

paymand commented Dec 9, 2014

@sebv: any idea? (looks like spawn cannot find the Java binary)

@sebv
Copy link
Member

sebv commented Dec 9, 2014

Just check PATH and JAVA_HOME at the time when appium is running.

@vijay0850
Copy link
Author

Now I changed the Java version to 1.7. But I still gtting same issue

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\elcot>java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)

C:\Users\elcot>

JAVA_HOME = C:\Program Files\Java\jdk1.7.0_71

PATH = C:\Program Files\Java\jdk1.7.0_71\bin;%ANDROID_HOME%/tools;%ANDROID_HOME%/platform-tools;C:\Program Files\nodejs\

@sebv
Copy link
Member

sebv commented Dec 9, 2014

Check the variables when and where appium is running not in a random terminal.

@vijay0850
Copy link
Author

You mean this
C:\Users\elcot\Downloads\Vijay_Important\Appium>java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)

@vijay0850
Copy link
Author

In error log it showing Java 1.5

info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)

info: [debug] Using local app from desired caps: D:\AndroidApps\test.apk
info: [debug] Creating new appium session 9ea241fb-f072-484d-8730-57ba33ee49ad
error: Failed to start an Appium session, err was: Error: 'java -version' failed. Error: spawn ENOENT

Shall I try with java 1.5 update?

@sebv
Copy link
Member

sebv commented Dec 9, 2014

Nope nothing to do with Java version it's the way Java is installed. Did you restart your terminal?

@vijay0850
Copy link
Author

yeap now only i restarted my pc

@sebv
Copy link
Member

sebv commented Dec 9, 2014

If you cannot figure out, just edit C:\Users\elcot\Downloads\Vijay_Important\Appium\node_modules\appium\lib\devices\android\android-common.js and add some debug line 1033:

console.log("Env-->", process.env);

@brenol
Copy link

brenol commented Dec 9, 2014

Hey guys,

I started having this issue after updating Appium to 1.3.4. I am using Ubuntu 14.10.
I spent a lot of time trying to fix it but I just installed 1.2.4 via npm and it's now working.

I ran:

npm install appium
(This installs 1.3.4, had same issue as the OP)
npm uninstall appium
npm install appium@1.2.4

I also thought my Java had something wrong (spent sometime with the JAVA_HOME and update-alternatives) but it only got fixed after changing Appium version.

FYI:

$ echo $JAVA_HOME
/usr/lib/jvm/java-7-oracle
$ which java
/usr/lib/jvm/java-7-oracle/bin/java
$ java -version
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)

Using your tip @sebv I got this from appium 1.3.4:

JAVA_HOME: '/usr/lib/jvm/java-7-oracle'

I also checked on android-common.js in 1.2.4 and I see that this functionality that looks for Java is not there, so I did not add any debug information to it. It seems I'm always falling in the if in line 1040, even though JAVA_HOME is set correctly from what I see.

Thanks!

@sebv
Copy link
Member

sebv commented Dec 9, 2014

And the %PATH% is correct?

@vijay0850
Copy link
Author

yeah as I mentioned early it was correct only

@vijay0850
Copy link
Author

info: [debug] Getting Java version

Env--> { ALLUSERSPROFILE: 'C:\ProgramData',
ANDROID_HOME: 'C:\Users\elcot\Downloads\Vijay_Important\adt-bundle-windows-x86-20140702\sdk',
APPDATA: 'C:\Users\elcot\AppData\Roaming',
CommonProgramFiles: 'C:\Program Files\Common Files',
COMPUTERNAME: 'ELCOT-PC',
ComSpec: 'C:\Windows\system32\cmd.exe',
FP_NO_HOST_CHECK: 'NO',
HOMEDRIVE: 'C:',
HOMEPATH: '\Users\elcot',
JAVA_HOME: 'C:\Program Files\Java\jdk1.7.0_71',
LOCALAPPDATA: 'C:\Users\elcot\AppData\Local',
LOGONSERVER: '\ELCOT-PC',
NODEJS: '"C:\Program Files\Nodejs"',
NUMBER_OF_PROCESSORS: '2',
OS: 'Windows_NT',
Path: 'C:\Program Files\Java\jdk1.7.0_71\bin;C:\Users\elcot\Downloads\Vijay_Important\adt-bundle-windows-x86-20140702\sdk/tools;C:\Users\elcot\Downloads\Vijay_Important\adt-bundle-windows-x86-20140702\sdk/platform-tools;C:\Program Files\nodejs;C:\Users\elcot\AppData\Roaming\npm',
PATHEXT: '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
PROCESSOR_ARCHITECTURE: 'x86',

@vijay0850
Copy link
Author

appium also detected the path of java sdk

@sebv
Copy link
Member

sebv commented Dec 9, 2014

Try this, need to understand why this would not work.

node -e "require('child_process').exec('java -version', function (err, stdout, stderr) { console.log(arguments); });"

@vijay0850
Copy link
Author

where at 1033 line of android common.js file?

@sebv
Copy link
Member

sebv commented Dec 9, 2014

no just from command line.

@brenol
Copy link

brenol commented Dec 9, 2014

Hi @sebv,

Just ran your command but I was also debugging on my side here.

My issue is that I have a _JAVA_OPTIONS set on my /etc/environment.

When running that command on cli I got this:

{ '0': null,
'1': '',
'2': 'Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true\njava >version "1.7.0_72"\nJava(TM) SE Runtime Environment (build 1.7.0_72-b14)\nJava HotSpot(TM) >64-Bit Server VM (build 24.72-b04, mixed mode)\n' }

My problem is that on Line 1035 it gets the index from the split (the _JAVA_OPTIONS) and thats why it's not working for me.

Thanks!

@vijay0850
Copy link
Author

I got this for ur command @sebv

C:>node -e "require('child_process').exec('java -version', function (err, stdou
t, stderr) { console.log(arguments); });"
{ '0': { [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn'
},
'1': '',
'2': '' }

C:>

@sebv
Copy link
Member

sebv commented Dec 9, 2014

Try to change the java -version command to make it work, I cannot think of any reasons why this would not work.

@vijay0850
Copy link
Author

Okay no problem I will try with older version of appium. Thanks for all to replying my issues and for helpful suggestion.

@vijay0850
Copy link
Author

@brenol can u please help me to run appium in 1.2.4 version please....

@brenol
Copy link

brenol commented Dec 9, 2014

@vijay0850 did you install appium using npm? I don't have a Windows environment here set up so I can't really help.

If you installed Appium using npm, then you can run this:

npm uninstall -g appium
npm install -g appium@1.2.4

I'm not sure if it'll be added to your path directly but it might.

@vijay0850
Copy link
Author

okay i will try this thanks

@sebv
Copy link
Member

sebv commented Dec 9, 2014

Thought of one thing, maybe it's a permission issue.

@vijay0850
Copy link
Author

I already tried with disabling firewall also..... :(

On Wed, Dec 10, 2014 at 3:58 AM, seb vincent notifications@github.com
wrote:

Thought of one things, maybe it's a permission issue.


Reply to this email directly or view it on GitHub
#4229 (comment).

Regards,

@sebv
Copy link
Member

sebv commented Dec 10, 2014

Not the firewall, the actual files permissions, or the permissions of one of the parent dirs.

@vijay0850
Copy link
Author

I gave all user permission still im getting java version failed

@vijay0850
Copy link
Author

I need solution for these issues.........

@vijay0850
Copy link
Author

need to raise new ticket again?

@yahman72
Copy link

I had the same issue i.e.

  1. when starting a session appium fails with Error: 'java -version' failed. Error: spawn ENOENT
  2. running java -version, in the same console (= windows command prompt) where appium was running, works fine

The problem was the %PATH% variable, in addition to the JAVA_HOME it must also contain the windows system directories (i.e. %SystemRoot%\system32;%SystemRoot%), because behind the scenes appium uses something in those directories when launching java -version

@mervin29
Copy link

Hi Vijay,
I faced the same issue. It got resolved by installing node.js.

@stkomitov
Copy link

I can confirm that adding %SystemRoot%\system32;%SystemRoot% to PATH variable solves the problem. Thank you @yahman72

@beemi
Copy link

beemi commented Jun 2, 2015

By adding [%SystemRoot%\system32;%SystemRoot%] to the System PATH,issue Fixed
Thank you

@canb0
Copy link

canb0 commented Sep 4, 2015

I also have the same problem.
When I run "java -version" there's no problem but when I execute cmd.exe /s /c "java -version" I got an error. I have JAVA_HOME in my PATH variable. How can I debug this problem.

"Specified path cannot be found" (sorry for mistranslation) is captured at the 1st line
I am using Windows 8.1
command

@yahman72
Copy link

yahman72 commented Sep 4, 2015

Looks like that error has nothing to do with your cmd.exe /S /c "java -version" command.
You have the same error before you have executed your command = probably there's something wrong with your windows environment/installation i.e. just google for that that "Sistem belirtilen..." error message.
For example:
http://stackoverflow.com/questions/13316682/windows-cmd-exe-the-system-cannot-find-the-path-specified

@canb0
Copy link

canb0 commented Sep 4, 2015

man you're great, that was the problem. My old ansicon installation was in registry and that was the root cause.

@mmcintyre123
Copy link

mmcintyre123 commented May 31, 2016

Hi @sebv, I'm having the same issue and at a total loss. I am on Windows 10, have both %SystemRoot%\system32 and %SystemRoot% on my PATH variable, my java location on my path variable, and JAVA_HOME defined. Yet when I try to start appium in the GUI with "Pre-Launch" application, I get

error: Could not pre-launch appium: Error: 'java -version' failed. Error: Command failed:

C:\WINDOWS\system32\cmd.exe /s /c "java -version"
'java' is not recognized as an internal or external command,
operable program or batch file.

which makes no sense to me since java -version works fine in cmd.exe:

$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

So I ran the command you mentioned:

$ node -e "require('child_process').exec('java -version', function (err, stdout, stderr) { console.log(arguments); });"

Which gives:

{ '0': null,
  '1': '',
  '2': 'java version "1.7.0_79"\r\nJava(TM) SE Runtime Environment (build 1.7.0_79-b15)\r\nJava HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)\r\n' }`

I just restarted my computer but still the same error. I am truly at a loss, would appreciate any help. Is it even important to run with the "Pre-Launch" application?

@mmcintyre123
Copy link

Noticing this issue was closed I just created a new one - #6542. Would appreciate any help!

@reddyontp
Copy link

Hi One & all,
Here am getting this issue,not able to fix this issue,can anyone guide ,how to fix this issue. & what is the Cause.
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT)","origValue":"'java -version' failed. Error: spawn ENOENT"},"sessionId":null}

@mmcintyre123
Copy link

mmcintyre123 commented Feb 7, 2018

Did you update to the latest java jdk and jre and add both to your user path? How are you starting Appium? Also check your node version, java version, Appium version. I assume you're using Windows?

@mmcintyre123
Copy link

mmcintyre123 commented Feb 7, 2018

Also confer issue #6542.

@reddyontp
Copy link

reddyontp commented Feb 8, 2018 via email

@mmcintyre123
Copy link

I'm not Appium support - just a user offering tips. But happy to help if I can. I assume the 1.4.13.1 is the version of Appium Server your desktop client is running - is that the latest client version?

The latest desktop client is 1.3.2: https://github.com/appium/appium-desktop/releases/tag/v1.3.2. Have you tried running your tests without the GUI, i.e. from the command line with a later version of Appium Server?

The java version actually didn't show up above, can you post it in text format?

Lastly, can you post your whole (or at least more) log output like the first post above which includes the desired capabilities you are passing in?

Best,
mmcintyre123

@mmcintyre123
Copy link

Your client must be out of date. Here is what the latest (1.3.2) looks like. Notice it's using Appium Server version 1.7.2:
image

@lock
Copy link

lock bot commented Apr 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests