ANDROID_HOME is not set and "android" command not in your PATH


#1

Hi Guys,
I’m working with OS X Yosemite and tried to add android platform in my project, but when i add android platform it’s return error

Running command: /Library/WebServer/Documents/xxxxx/platforms/android/cordova/build 
[Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.]
Error: /Library/WebServer/Documents/xxxxx/platforms/android/cordova/build: Command failed with exit code 2
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)

Actualy, I’ve already set environment variable in ~/.bash_profile like this

# export ANDROID_HOME="/Users/donny/Documents/android/sdk"
# source ~/.bash_profile

it’s still won’t work, when i ran this command

# echo $ANDROID_HOME

it’s return blank or empty.

Thank You, Any help will appreciate


#2

try sudo export…

# sudo export ANDROID_HOME="/Users/donny/Documents/android/sdk"

#3

Hi @harshitgoel96, thanks for your response
Yup, it’s has using root access already.


#4

and “android” command not in your PATH

you also need to add android to your class path…

android-sdk\tools
and
android-sdk\build-tools should be set in ur path


#5

Yep, I had already

nano ~/.bash_profile

#Android
export PATH=${PATH}:/Users/donny/Documents/android/sdk/platform-tools:/Users/donny/Documents/android/sdk/tools
export ANDROID_HOME=/Users/donny/Documents/android/sdk

it’s work when i type this command

source ~/.bash_profile

then i check my $ANDROID_HOME

echo $ANDROID_HOME
$ /Users/donny/Documents/android/sdk

but when i close my terminal and open up again, it return error again T_T
i check $ANDROID_HOME again

echo $ANDROID_HOME
$

by the way, before i upgrade my os x to yosemite everything alright.
any help ?


#6

well this seems to be a problem of the fact that the variable is set only for that particular terminal session, and not for the entire system… i am not an expert with OS X… so u need to figure out how to set the variable for entire system and not for a particular terminal session


#7

You are right @harshitgoel96 :wink:
I just thinking there are any peoples who solving this issue hehehe
and they would like to help me
But thanks @harshitgoel96
By the way, in brew had similar problem https://github.com/Homebrew/homebrew/issues/29843 OOT 3:


#8

I have this in my path for android sdk.

  export PATH=${PATH}:/Applications/Android\ Studio.app/sdk/platform-tools:/Applications/Android\ Studio.app/sdk/tools
  export JAVA_HOME=$(/usr/libexec/java_home)
  export PATH=${JAVA_HOME}/bin:$PATH
  export PATH=/usr/local/bin:$PATH

#9

hi @mhartington hanks for your response
Yep, I’ve follow your instruction and execute my bash_profile

# source ~/.bash_profile

it’s works nicely in current terminal when i type android, but when i open up another terminal then type android it’s return

zsh: command not found: android

Thanks,


#10

Hmm, so why would you put that in your bash_profile if your terminal uses zsh? If you’re using zsh, you should put this in your zshrc

Also in my case, I installed Android studio to get the sdk so that could be why android isn’t found.


#11

by the way, where i have to register ANDROID_HOME in zsh ? i don’t know exactly …
I’m using eclipse, is it different or there is have plus options ?

Thanks,


#12

Hi all,

Helpful hint for linux users who find themselves here. Make sure your editing the right .bash_profile, I kept getting the above error response until I realized I was editing the “/home/user/.bash_profile” instead of the “/root/.bash_profile”

OPEN terminal as root

nano ~/.bash_profile

export ANDROID_HOME=/root/Android/Sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

EXIT > SAVE

source ~/.bash_profile
echo $ANDROID_HOME

#13

Hi @Isiaha
Thanks for your response
I’ve already edit .bash_profile inside root directory. check this out

and for this

# source ~/.bash_profile
# echo $ANDROID_HOME

it success, but when i open another tab/terminal or after restarting the computer, it’s return error/blank again ~_~

Thanks


#14

I get the same error on ubuntu despite having ANDROID_HOME on my path. I have no idea what the problem is. The path is set in my .profile file.


Upgrade warning - for the CLI to run correctly,
it is highly suggested to upgrade the following:

Please update your Node runtime to version >=0.12.x


Running command: /home/johnboy14/ionic/myApp/hooks/after_prepare/010_add_platform_class.js /home/johnboy14/ionic/myApp
add to body class: platform-android
Running command: /home/johnboy14/ionic/myApp/platforms/android/cordova/build
[Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.
Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.]
ERROR building one of the platforms: Error: /home/johnboy14/ionic/myApp/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/johnboy14/ionic/myApp/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)


#15

make sure you wrote environment variable in the right place

$ cd $HOME
$ nano .bash_profile

do not wrote if u are in root access like this

# cd $HOME
# nano .bash_profile

just make sure after u are in the right place type this

$ pwd

it should print /Users/your_user

if you are in root access it will print /var/root

I hope it help you
Thank you


#16

I’ve set the variable in my .profile, .bashrc and bash_profile files and I still get the same error. It is set as an environment variable.

:~/ionic/myApp$ env
ANDROID_HOME=/opt/android-sdk


#17

What about your PATH?
Does it work when you run android command ?


#18

yes. Both Android, Cordova and Ionic are on the path.


#19

just make sure u add $PATH at the last of your environment path

for example

$ cd $HOME
$ nano .bash_profile

then it will open the nano editor

# your path
export PATH = "/directory/path:$PATH"

then save that, after that you have to execute this command to make sure your new path is registered

$ source .bash_profile

to test if your new path has registered just type this

$ echo $PATH

i hope it will help you

Thanks


#20

It is currently on my path.

/ionic$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/android-sdk/tools:/opt/android-sdk/platform-tools:/opt/node/bin:/opt/android-sdk/tools:/opt/android-sdk/platforms-tools:/opt/android-sdk/tools:/opt/android-sdk/platform-tools:/opt/node/bin