7

When I run tns run android or tns doctor I get an error that the ANDROID_HOME environment variable is not set. Yet it's clearly set. Mac OSX Sierra 10.12.3.

bash-3.2$ tns run android
The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.
bash-3.2$ $ANDROID_HOME
bash: /Users/rlangton/Library/Android/sdk: is a directory
bash-3.2$
Ryan Langton
  • 6,294
  • 15
  • 53
  • 103
  • 1
    Permissions is my first guess. I don't use a Mac often enough to know for certain but I've seen others report using sudo when setting up things works and others who don't need sudo. So maybe the cli doesn't have the perms to access :/ – Brad Martin Apr 01 '17 at 17:09
  • see here https://github.com/NativeScript/nativescript-cli/issues/1097 & if u are using VS then see here http://stackoverflow.com/questions/31792693/how-to-make-visual-studio-2015-installer-know-that-i-already-have-android-sdk – Mohammad Tauqir Apr 17 '17 at 11:24
  • Try set your sdk location path that may be help you [android sdk locaiton path](http://stackoverflow.com/questions/19986214/setting-android-home-enviromental-variable-on-mac-os-x) – parik dhakan Apr 22 '17 at 05:05

2 Answers2

7

If you're using bash then you need to update the ~/.bash_profile file. In my case, I'm using ZSH so I needed to edit ~/.zshrc file.

nano ~/.zshrc

Add the export line below:

if [ -f /Users/{myusername}/.tnsrc ]; then
    source /Users/{myusername}/.tnsrc
    export ANDROID_HOME=/Users/{myusername}/Library/Android/sdk
fi

Ctrl + O to save, Ctrl + X to exit. Restart the terminal. Now echo $ANDROID_HOME shows the correct path every time.

Nitin Kabra
  • 3,146
  • 10
  • 43
  • 62
Ryan Langton
  • 6,294
  • 15
  • 53
  • 103
7

Open/create .profile like this

vim ~/.profile

add the following lines to the end of the .profile file.

export ANDROID_HOME=${HOME}/Library/Android/sdk

load the profile using the command

source ~/.profile

You should have it working I guess. This is what I did to get this configured.

rahulrvp
  • 2,006
  • 1
  • 19
  • 26
  • I am using windows and I am also getting some type of same error `The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.` Can you tell me what to do? – Climb Tree Apr 25 '17 at 14:04
  • @ClimbTree please try editing the environmental variables and adding a variable `ANDROID_HOME ` with value as path to the `sdk` folder. – rahulrvp Apr 26 '17 at 04:01