Failed to start an Appium session, err was: Error: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path

@penguinho @rusuo @tarunsujit @sebv
Still this issue is noticed with the appium 1.3.3 and 1.3.6 and 1.4.3 … while starting appium server through java code the below error log is displayed .

Using MAC MACHINE osx yosemite

Appium start server code :+1:
public static void startAppiumServer() throws ExecuteException,
IOException, InterruptedException {

CommandLine command = new CommandLine(
“/usr/local/bin/node”);
command.addArgument(
“/usr/local/lib/node_modules/appium/bin/appium.js”,
false);
command.addArgument("–address", false);
command.addArgument(“127.0.0.1”);
command.addArgument("–port", false);
command.addArgument(“4723”);
command.addArgument("–no-reset", false);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);

Thread.sleep(5000);
System.out.println(“Appium server started”);

}

Error Log :
[TestNG] Running:
/private/var/folders/gd/c4rghf9d5zv8phtq6zbf99t40000gp/T/testng-eclipse–418167106/testng-customsuite.xml

Appium server stop
Appium server started
[36minfo[39m: Welcome to Appium v1.4.3 (REV a357c7fa73222315dd85c3d2dd8334767cca1b0d)
[36minfo[39m: Appium REST http interface listener started on 127.0.0.1:4723
[36minfo[39m: [debug] Non-default server args: {“address”:“127.0.0.1”,“noReset”:true}
[36minfo[39m: Console LogLevel: debug
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
[36minfo[39m: [37m–>[39m [37mPOST[39m [37m/wd/hub/session[39m [90m{“desiredCapabilities”:{“platformVersion”:“5.0.1”,“platformName”:“Android”,“deviceName”:“HTC One_M8”,“browserName”:“Android”,“appActivity”:“com.digby.lptester.activity.DetailsActivity”,“uuid”:“SH43WWM15617”,“appPackage”:“com.digby.lptester”}}[39m
[36minfo[39m: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
[36minfo[39m: [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. : uuid
[36minfo[39m: [debug] Didn’t get app but did get Android package, will attempt to launch it on the device
[36minfo[39m: [debug] Creating new appium session e408a90a-d0a9-42e9-9b68-7f7c3659607d
[36minfo[39m: Starting android appium
[36minfo[39m: [debug] Getting Java version
[36minfo[39m: Java version is: 1.8.0_25
[36minfo[39m: [debug] Checking whether adb is present
[33mwarn[39m: The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.
[36minfo[39m: [debug] executing cmd: which adb
[36minfo[39m: [debug] Cleaning up android objects
[36minfo[39m: [debug] Cleaning up appium session
[31merror[39m: Failed to start an Appium session, err was: Error: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.
[36minfo[39m: [debug] Error: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.
at [object Object]. (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/adb.js:126:12)
at ChildProcess.exithandler (child_process.js:758:5)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Socket. (child_process.js:1183:11)
at Socket.emit (events.js:107:17)
at Pipe.close (net.js:485:12)
[36minfo[39m: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.)”,“origValue”:“Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.”},“sessionId”:null}
[36minfo[39m: [37m<-- POST /wd/hub/session [39m[31m500[39m[90m 874.709 ms - 342[39m [90m[39m

Please help me out for the above error since from one week back i am facing this issue with android platform.

What is the value of ANDROID_HOME. If you don’t know how to get that, from the command line type, ‘echo $ANDROID_HOME’. You could also just type, ‘export’ and see if the variable is set in the output.

This is a good resource for info on environment variables:

http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-terminal-only/

Others are just a Google search away…

Hi Rakesh,

Did you get any solution of this issue. I am also facing same issue please tell me how you resolved this issue.

Thanks in advance.

You can check all the environment variables are set up properly or not by doing this:

in terminal:

  1. type export

make sure you have

  1. ANDROID_HOME set up to /Users/{}/Library/Android/sdk/
  2. JAVA_HOME set up to /Library/Java/JavaVirtualMachines/jdk{}/Contents/Home
  3. Path contains path for /Library/Android

If not set up this paths in ~/.bash_profile file so that you don’t have to set up everytime.

Happy coding!

Sorry FOR THE delay Prasad,

The solution of the issue is i think your running scripts through Eclipse IDE and here the solution you need to select android Home in the eclipse IDE .

To elaborate the solution (Set Path in the Eclipse : MAC machine same for Windows)

Launch your eclipse ->Click on Run -> Click on Run configurations
Select the Environment Tab -> Now set Android_Home path in the eclipse .

Thanks,
Rakesh kumar

1 Like

I’m having the same issue now, yesterday everything worked. Now I have this error message too. I did not changed anything at all, I just restarted the Mac where the Appium server is running…

At least for my case I understand why it fails. I am using SSH to start Appium with tmux - which is removing environment variables, including ADB, so I had to add them in the SSH command:

export ANDROID_HOME=/Users/qa/Library/Android/sdk/

I guess that could be one of quit a lot of reasons :wink:

Will you please elaborate your answer a bit more, I am also using appium on ubuntu , I am getting same error , and I am stuck

Hi…
I am Mac user and I have set all ANDROID_HOME in my bash profile correctly. My adb commands are working fine, but in Eclipse it gives error as “The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.Failed to start an Appium session, err was: Error: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.”
When I set Android_Home variable in eclipse locally using Run configuration, it works but I am having many tests classes in project, How I suppose to set Android_Home globally. (mac 10.11.3)

Please Help me to solve this.

You cannot run adb commands directly from Eclipse … it cannot find your adb home.
Add the adb path and run.
So instead of this : adb devices
Use this : path_to_ur_sdk/platform-tools/adb devices
NOTE : You should run it using java runtime with permissions (chmod).

Thanks,
Amarnath Rayudu