Search code examples
androidmacosnativescript

NativeScript ANDROID_HOME missing


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$

Solution

  • 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.