ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported

I started the Appium from Mac OS Big Sur terminal

I created Appium driver instance from code and tried to run script I getting the below error
driver = new AndroidDriver(service.getUrl(),capabilities);
Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. Read https://developer.android.com/studio/command-line/variables for more details
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘EPINHYDW0006’, ip: ‘fe80:0:0:0:182f:4373:ce6b:3332%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.16’, java.version: ‘11.0.11’
Driver info: driver.version: AndroidDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. Read https://developer.android.com/studio/command-line/variables for more details
at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:804:9)
at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:380:37)
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘EPINHYDW0006’, ip: ‘fe80:0:0:0:182f:4373:ce6b:3332%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.16’, java.version: ‘11.0.11’
Driver info: driver.version: AndroidDriver
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:216)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:225)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:37)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:89)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:99)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:97)
I tired Changing environment variable ANDROID_HOME to ANDROID_SDK_ROOT . Still getting the same error. Im struck here .

I changed ANDROID_HOME to ANDROID_SDK_ROOT and exported the path but still facing the same issue .

For Appium Desktop its working fine . It happens only when start Appium from terminal

Environment

Appium server : latest
Appium Java client : 7.6.0
Java : 1.11
IDE : Intellij

Need you support

Thanks,
Kiran

in terminal check that path to android exists:

$ echo $PATH
/usr/local/opt/ruby/bin:/Users/MY_USER/.gem/ruby/2.3.0/bin:/Users/MY_USER/Library/Android/sdk/tools:/Users/MY_USER/Library/Android/sdk/platform-tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:xxxx

see we have ‘Library/Android/sdk/tools’ + ‘Library/Android/sdk/platform-tools’

Hi

Appreciate for your prompt response . The issue got solved by keeping the Android simulator instance open and then tun the test

Thanks,
kiran