When I Run My Frist script on

warn: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
info: Welcome to Appium v1.4.0 (REV 8f63e2f91ef7907aed8bda763f4e5ca08e86970a)
info: Appium REST http interface listener started on 127.0.0.1:4724
info: [debug] Non-default server args: {“address”:“127.0.0.1”,“port”:4724,“logNoColors”:true,“platformName”:“Android”,“platformVersion”:“18”,“automationName”:“Appium”}
info: Console LogLevel: debug
info: → POST /wd/hub/session {“desiredCapabilities”:{“platformVersion”:“6.0.0”,“app”:“C:\Users\admin1\workspace\NewAppium\Apps\app-universal-debug.apk”,“deviceName”:“Google_Nexus_5_6.0.0_API_23”,“platformName”:“Android”,“device”:“Android”}}
info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.7.0_79)
info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : device
info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] No appPackage desired capability or server param. Parsing from apk.
info: [debug] Using local app from desired caps: C:\Users\admin1\workspace\NewAppium\Apps\app-universal-debug.apk
info: [debug] Creating new appium session 69aca0ed-5680-4ee6-8305-17302ad7d4d2
info: Starting android appium
info: [debug] Getting Java version
info: [debug] Cleaning up android objects
error: Failed to start an Appium session, err was: Error: ‘java -version’ failed. Error: Command failed: ‘java’ is not recognized as an internal or external command,
operable program or batch file.

info: [debug] Cleaning up appium session
info: [debug] Error: ‘java -version’ failed. Error: Command failed: ‘java’ is not recognized as an internal or external command,
operable program or batch file.

at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:1057:17)
at ChildProcess.exithandler (child_process.js:641:7)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Socket.<anonymous> (child_process.js:956:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:465: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: Command failed: ‘java’ is not recognized as an internal or external command,\r\noperable program or batch file.\r\n)”,“origValue”:“‘java -version’ failed. Error: Command failed: ‘java’ is not recognized as an internal or external command,\r\noperable program or batch file.\r\n”},“sessionId”:null}
info: ← POST /wd/hub/session 500 49.840 ms - 414

Below Is My code which I am running

public class AppiumTest {

/**
 * @param args
 */
@SuppressWarnings("rawtypes")
private static final String TARGET_APP_PATH = "C:/AutomationSoftware/app-universal-debug.apk";
static String deviceName = "Google_Nexus_5_6.0.0_API_23";
private static final String TESTDROID_SERVER = "http://127.0.0.1:4724";
private static int counter;
@SuppressWarnings({ "rawtypes", "unused" })
public static void main(String[] args) throws InterruptedException, ExecuteException, IOException {
	// TODO Auto-generated method stub

	//protected AndroidDriver driver;
        File appDir = new File("/Users/admin1/workspace/NewAppium/Apps");
        File app = new File(appDir, "app-universal-debug.apk");


        DefaultExecutor executor = new DefaultExecutor();
        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();

        CommandLine launchEmul = new CommandLine("C:/Program Files/Genymobile/Genymotion/player");
        launchEmul.addArgument("--vm-name");
        launchEmul.addArgument("Google_Nexus_5_6.0.0_API_23");
        executor.setExitValue(1);
        //executor.execute(launchEmul,resultHandler);
        executor.execute(launchEmul, resultHandler);
        Thread.sleep(400);
        
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("device","Android");        
        //mandatory capabilities
        capabilities.setCapability("deviceName","Google_Nexus_5_6.0.0_API_23");
        capabilities.setCapability("platformVersion", "6.0.0");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("Automation", "Appium 1.4.0.0"); 
        capabilities.setCapability("platformName", "Android");

        //other caps
        capabilities.setCapability("app", app.getAbsolutePath());
        AndroidDriver<WebElement> driver =  new AndroidDriver(new URL("http://127.0.0.1:4724/wd/hub"), capabilities);		
        System.out.println("SetUp is successful and Appium Driver is launched successfully");
	 
}

}

Hi Amitcs100, which Java version you are using. If not yet installed, please install and then run the script.

Make sure java is on the PATH environment variable of the Appium server’s process.

I am using Java 1.7 Below is the Version Details :-

C:\Users\admin1>java -version
java version “1.7.0_79”
Java™ SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot™ 64-Bit Server VM (build 24.79-b02, mixed mode)

C:\Users\admin1>

Even After Adding JAVA_HOME and Adding the same In PATH Environment Variable still I see same Issue.

Hi afwang,

   When I gave the JAVA in PATH Environment Variable till /bin I am not seeing this Error Thank you.

But I am seeing other Error Below is the error :-

info: [debug] executing cmd: C:\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell “getprop ro.build.version.sdk”
info: [debug] Device is at API Level 23
info: [debug] executing cmd: C:\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell “pm list packages -3 com.certesnetworks.cryptoflow”
info: [debug] App is not installed
info: Installing App
info: [debug] executing cmd: C:\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell “mkdir -p /data/local/tmp/”
info: [debug] Removing any old apks
info: [debug] executing cmd: C:\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell “ls /data/local/tmp/*.apk”
info: [debug] No apks to examine
info: [debug] executing cmd: C:\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 push “C:\Users\admin1\workspace\NewAppium\Apps\app-universal-debug.apk” /data/local/tmp/84f412ddb2194706009b7302cff5f1c1.apk
info: [debug] Uninstalling com.certesnetworks.cryptoflow
info: [debug] executing cmd: C:\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell “am force-stop com.certesnetworks.cryptoflow”
info: [debug] executing cmd: C:\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 uninstall com.certesnetworks.cryptoflow
info: [debug] App was not uninstalled, maybe it wasn’t on device?
info: [debug] executing cmd: C:\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell “pm install -r /data/local/tmp/84f412ddb2194706009b7302cff5f1c1.apk”
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: C:\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 forward tcp:4724 tcp:4724
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] Sent shutdown command, waiting for UiAutomator to stop…
warn: UiAutomator did not shut down fast enough, calling it gone
error: Failed to start an Appium session, err was: Error: Command failed: error: cannot bind listener: cannot bind to 127.0.0.1:4724: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)

info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Error: Command failed: error: cannot bind listener: cannot bind to 127.0.0.1:4724: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)

at ChildProcess.exithandler (child_process.js:637:15)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)

info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: Command failed: error: cannot bind listener: cannot bind to 127.0.0.1:4724: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)\r\n)”,“killed”:false,“code”:1,“signal”:null,“origValue”:“Command failed: error: cannot bind listener: cannot bind to 127.0.0.1:4724: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048)\r\n”},“sessionId”:null}
info: ← POST /wd/hub/session 500 40416.131 ms - 520

Hello. I am facing the similar error. Could somebody please help me?
I am trying to run some dummy tests on Android emulator with Robot Framework.

WebDriverException: Message: A new session could not be created. (Original 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.)

Appium server log:

Launching Appium server with command: C:\Program Files\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --device-ready-timeout 5 --platform-name Android --platform-version 23 --automation-name Appium --log-no-color
info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
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”:“23”,“automationName”:“Appium”}
info: Console LogLevel: debug
info: → POST /wd/hub/session {“desiredCapabilities”:{“platformVersion”:“6.0”,“deviceName”:“emulator-5554”,“platformName”:“Android”,“appActivity”:“com.android.settings.Settings”,“appPackage”:“com.android.settings”}}
info: Client User-Agent string: Python-urllib/2.7
info: [debug] Didn’t get app but did get Android package, will attempt to launch it on the device
info: [debug] Creating new appium session 48ffc661-7021-4b7d-a142-88cb3de3f576
info: Starting android appium
info: [debug] Getting Java version
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: 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.

info: [debug] 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.

at [object Object].<anonymous> (C:\Program Files\Appium\node_modules\appium\lib\devices\android\android-common.js:1057:17)
at ChildProcess.exithandler (child_process.js:758:5)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1016:16)
at Socket.<anonymous> (child_process.js:1184:11)
at Socket.emit (events.js:107:17)
at Pipe.close (net.js:484:11)

info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not > be created. (Original error: ‘java -version’ failed. Error: Command failed:
C:\Windows\system32\cmd.exe /s /c "java -version"\n’java’ is not recognized as an internal or external command,\r\noperable program or batch file.\r\n)”,“origValue”:“‘java -version’ failed. Error: Command failed: C:\Windows\system32\cmd.exe /s /c "java -version"\n’java’ is not recognized as an internal or external command,\r\noperable program or batch file.\r\n”},“sessionId”:null}
info: ← POST /wd/hub/session 500 55.354 ms - 526

I also have Java installed:

PATH environment variable of the Appium server’s process ? So where exactly it should be? I don’t understand…

Do you have another process listening to that socket? What is the command line you use to launch Appium?

Whenever you interact with a computer system, you - the user - perform these interactions through an environment known as a shell. The shell can be a command line shell or a graphical shell, but in either case, it provides you a way to launch and manage your processes.

This environment contains a special variable known as PATH. The PATH variable is simply a list of filepaths to the various directories on your system that contain executable files (such as scripts or binary files).

An important piece of information is that every user process on your system (such as instances of Appium) has their own copy of this PATH variable. Whenever such a process wants to spawn a child process to run another program, the parent process needs the name of the executable file for the child process’s program to be available in one of the directories listed in the PATH environment variable (or the parent needs to use an absolute path, but that’s an unimportant side note for this particular case).

If java can not be found through one of the directories listed in the PATH variable, then Appium will fail when it tries to run Java. Since you’re using Windows, you should follow a guide to finding where you can set your PATH variable. Feel free to use your favorite web search engine to find additional articles, guides, or tutorials on setting this value.

Hi. Thanks for your answer.

I have Java in my shell path and it is still not working.
I tried:

C:\Program Files\Java\jdk1.7.0_79\bin

and

C:\Program Files\Java\jdk1.7.0_79

but it’s not working,

UPDATE:
Ok, I changed the order in PATH - for Java to be before the Appium and Android stuff and it looks like it get it. There is no such error anymore. Thanks.