Unable to start appium service by AppiumDriverLocalSerivce

Just to update on this thread for benefit of others, with below code I could get appiun node registered with Selenium HUB

String nodeConfigFilePath = “/Users/Mobile-Automation/Android-Automation/serenityAppiumFlipkart/EMULATOR_Nexus_4_1.json”;

    	 AppiumDriverLocalService driverLocalService = AppiumDriverLocalService
    			.buildService(new AppiumServiceBuilder()
    					.withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
    					.usingDriverExecutable(new File("/usr/local/bin/node"))
    					//.withIPAddress("127.0.0.1")
    					.usingPort(4445)
    					//.withArgument(GeneralServerFlag.UIID, "123456")    					
    					//.withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER,
    					//		"" + 2252)
    					//.withArgument(GeneralServerFlag.CHROME_DRIVER_PORT,
    					//		"" + client.getChromeDriverport())
    					//.withArgument(GeneralServerFlag.NO_RESET)
    					.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
    					.withArgument(GeneralServerFlag.LOG_LEVEL, "debug")
    					.withArgument(GeneralServerFlag.CONFIGURATION_FILE, nodeConfigFilePath));
    	//Logger.info("Server url: " + driverLocalService.getUrl());
    	driverLocalService.start();

Before you run this program, make sure to try it out from command line with below command

appium --nodeconfig EMULATOR_Nexus_4_1.json --port 4445

In case you do something wrong as appium --nodeconfig EMULATOR_Nexus_4_1.json --bp 2252, you will get nice output about flags usage

Couple of open queries still as below

  1. it didn’t work with usingAnyFreePort(), I had to explicitly mention port number.

  2. I could register android emulator node, even when it was not in open state, not sure if this is valid ?

Regards,
Vikram