Encountered internal error running command: Error: Could not find 'adb' in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the correct Android SDK root directory path

OS Platform: MacOS

I have my own node application and with that I am trying to execute below appium command to start appium server:
/usr/local/bin/node /usr/local/lib/node_modules/appium/build/lib/main.js --address 0.0.0.0 --port 4723

Now problem is it works successfully if this command or my node application is executed via terminal, on directly running app by double clicking appium gives the below error:

appium server stdout: [BaseDriver] Session created with session id: 3c772bb0-4c0d-4687-bb5b-d475d039ad7b[UiAutomator2] Starting 'com.google.android.apps.messaging' directly on the device[ADB] 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.
/Applications/myapp.app/Contents/Resources/app/scripts/appiumConfigHandler.js:20 appium server stdout: [debug] [UiAutomator2] Deleting UiAutomator2 session
/Applications/myapp.app/Contents/Resources/app/scripts/appiumConfigHandler.js:20 appium server stdout: [debug] [BaseDriver] Event 'newSessionStarted' logged at 1594207927588 (17:02:07 GMT+0530 (India Standard Time))
/Applications/myapp.app/Contents/Resources/app/scripts/appiumConfigHandler.js:20 appium server stdout: [debug] [W3C] Encountered internal error running command: Error: Could not find 'adb' in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the correct Android SDK root directory path.[debug] [W3C]     at ADB.getBinaryFromPath (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/tools/system-calls.js:140:11)
/Applications/myapp.app/Contents/Resources/app/scripts/appiumConfigHandler.js:20 appium server stdout: [debug] [W3C] Destroying socket connection
/Applications/myapp.app/Contents/Resources/app/scripts/appiumConfigHandler.js:20 appium server stdout: [HTTP] <-- POST /wd/hub/session 500 5367 ms - 791
/Applications/myapp.app/Contents/Resources/app/scripts/appiumConfigHandler.js:20 appium server stdout: [HTTP] 

I have ANDROID_HOME already settled up in ~/.bash_profile and even platform tools, build tools and tools are all are in the bash profile.

Please suggest what could be the solution for setting up appium in such a way so that it can run globally this not only from terminal.

~/.bash_profile is not used in ‘non-interactive’ shell sessions, such as one that is created when you ‘double click’ an app.

Rather you should put this information in ~/.bashrc

https://fileinfo.com/extension/bashrc

It’s either that or your application is executing under a different user. You can see if that’s so with the ActivityMonitor.

Hi reed, It did not work with bashrc, application is also executing under same user, then I worked it out with using a plist to run shell script file which sets all the paths of the bash_profile to globally,

Solution Reference: https://stackoverflow.com/questions/135688/setting-environment-variables-on-os-x

but I am still getting issue with Carthage. But in the same way, I am not able to set carthage as globally, carthage is installed properly and in working state, it is launching application when starting from terminal, so I guess again same environment issue.

Below is the issue I am getting with appium:
appium server stdout: [debug] [W3C] Encountered internal error running command: Error: Unable to launch WebDriverAgent because of xcodebuild failure: not found: carthage

Any solution for Carthage? How can I make it available?

Please follow this step & your issue may be resolved:
https://youtu.be/-6C-CMqSk

Can you add path to Carthage to this script and put it in $PATH?

Hi Sushil, This youtube link says video unavailable.

yes Wreed, I have tried this:

Below is my contents of bash_profile:

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export PATH=$PATH:/usr/local/Cellar/carthage/0.35.0/bin
export ANDROID_HOME=/Users/arun/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/build-tools/28.0.3
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=${PATH}:/usr/local/mysql/bin/
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home

Can you check these values in your code with some print statements before you hit the error? That way you can see for sure what exactly is getting to your application.

After that I’d try messing around with your script. I don’t know the difference between ‘${PATH}’ and ‘$PATH’, so I’d be curious if that made some kind of difference. Maybe try refactoring your ‘export PATH’ statements into less statements.

You might also include in your print statements the value of $SHELL. Just in case :wink:

Hi Wreed,

Output for “echo $PATH” from the application execution environment:
“/usr/bin:/bin:/usr/sbin:/sbin”

Output for “echo $SHELL” from the application execution environment and Terminal:
“/bin/zsh”

here zsh is unix executable.

Wow. So zsh won’t read .bash_profile or .bashrc files. Super glad I asked what I thought at the time might be a dumb question. You can set these environment variables in one of the 5 zsh startup files:

http://zsh.sourceforge.net/Intro/intro_3.html

It is recommended here that you put them in ~/.zshenv