How to set the environmental variable for SDK on MAC machine

2.3k Views Asked by At

In MAC machine, I setup the environmental variables for ANDROID SDK

Opened the terminal & entered the following commands

 export ANDROID_HOME=/Applications/android-sdk-macosx export
 PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

In the terminal I verified the path by typing export

PATH

In the above image, the PATH is appended with some other values whether those appended value is the issue or not?

Then, When I try to run it from eclipse, an error message is displayed like Console Error

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.) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 350 milliseconds

Suggestions and comments are welcome.

3

There are 3 best solutions below

0
On BEST ANSWER

I set those environmental as System-wide environmental variables. and it works now.

Previously I didn't set the environmental variable(ANDROID_HOME) as system-wide variable, that is the reason why the ANDROID_HOME variable is invisible in Eclipse Environment settings.

To set the ANDROID_HOME as System-wide environmental variable, I have used the following commands in terminal and some settings in Eclipse.

Terminal:

Run sudo nano /etc/launchd.conf
Add setenv ANDROID_HOME /Users/selvakumar/Documents/android-sdk-macosx
Then either restart or run launchctl < /etc/launchd.conf; sudo launchctl < /etc/launchd.conf

Eclipse:

Then the variable becomes visible in the Eclipse--> Run Configurations--> Environment -->Select-->ANDROID_HOME then I checked the ANDROID_HOME variable and click apply. Run the code with your new Run configuration settings. That made my code to work.

1
On

you need to set the path in .bash_profile

export JAVA_HOME=$(/usr/libexec/java_home)
# The next line updates PATH for the Google Cloud SDK.
source '/Users/vinay.maneti/google-cloud-sdk/path.bash.inc'
export PATH=$PATH:/Users/vinay.maneti/Library/Android/sdk/platform-tools/
8
On

You have to add them to .bash_profile and .bashrc

.bash_profile is the file which will be called whenever you open terminal and .bashrc will be called to load environment variables outside of terminal. So create two files

  1. .bash_profile in your HOME directory and store all the environment variables there
  2. .bashrc - write a line to execute .bash_profile

Eg:

echo 'export PATH=/usr/local/bin:$PATH' >>~/.bash_profile
echo '. .bash_profile' > ~/.bashrc

Edit : Setting the path directly in .bash_profile

Fill the path using vim editor.

vi ~/.bash_profile
export ANDROID_HOME=/Applications/android-sdk-macosx 
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
:wq

Then execute the .bash_profile once

. .bash_profile