Error trying run programmatically Appium - Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported, using C# and visual studio

Hello community

I’m working with Appium C# in MacOS environment but when I try run my current code for Android device had as result “Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported.Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported.”

I verified that environment variables have set correctly and those are correctly set, when I run echo $ANDROID_HOME return me the correct value:


I verified too in Visual Studio the configuration and set in Tools - Preferences - SDK Locations - Android and verify in Tools - Preferences - Tools for Unity - General and put the path of Android Studio in the option ‘Preferred Android SDK root’

Specific Error:
OpenQA.Selenium.WebDriverException : An unknown server-side error occurred while processing the command. Original error: Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. Read for more details

MacOS Ventura: 13.5
Visual Studio 17.6.3
Android Studio 2022.3.1 Giraffe

I hope someone can help me, thank you

Have you added $ANDROID_HOME in $PATH variable?

You can try to run “echo $PATH”.

I think that $ANDROID_HOME and $PATH are correctly set, on my .zshrc file I have those expectations


export ANDROID_HOME=/Users/admin/Library/Android/sdk
export ANDROID_SDK_ROOT=/Users/admin/Library/Android/sdk
export ANDROID_AVD_HOME=/Users/admin/.android/avd
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH

export PATH=$ANDROID_HOME/emulator:$PATH
export PATH=$ANDROID_HOME/sources:$PATH
export PATH=$ANDROID_HOME/bundle-tool:$PATH


export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH

I don’t know if I missing some configuration

Can you write the $PATH value?

Execute echo $PATH in a shell.

Sure, when I type echo $PATH, I have this result:



If you use Appium Server GUI you have to set the variables there as well

Hi Flavio thanks for your kind answer.

I checked the configuration and I see that the path correctly of JAVA_HOME and ANDROID_HOME, are similar as you show me.

I don’t know why appears the error when try to run my test from code, when I launch Appium Server Gui and Appium Inspector all works good, but from code doesn’t work.

This means from Visual Studio, correct? What if you run code from Terminal?

Yes sir it is from Visual Studio for Mac, I tried run the test cases from Terminal using the dotnet test command and does not appear the error I sailed on the title of the this post

Example command: dotnet test /Users/{YOURPATH}/{YOURPROJECT}.dll

Thanks a lot @wreed and @Flavio_Di_Carlo for your help with this issued I have had

So just so we are complete, it seems that you just need to add environment variables to your Visual Studio. Here are some instructions to do so:

Hi @wreed , I applied the answer that show me in StackOverflow but doesn’t work for me

But I continue with this issue, executing from Visual Studio for Mac:

Well, we’ve established that it’s not an Appium issue. Could try to continue to troubleshoot with Microsoft help:

Or could try another IDE. It’s really up to you.

I encountered a similar situation on Linux, where after setting up the environment variables, it is necessary to restart Appium. If the terminal in which Appium is running does not update the $ANDROID_HOME variable, the Appium Inspector will keep prompting this error.

In this case on both Linux and Mac you can restart the shell with this command:

exec $SHELL

Or you can source the shell’s startup scripts where you set the ENV VAR like this:

source <startup_script>

Example: source ~/.bashrc

1 Like