I am trying to build android for ionic in linux but its showing me an error like this
[Error: Failed to find \'ANDROID_HOME\' environment variable.
Android Home should be the root folder of SDK.
export ANDROID_HOME="$HOME/android-sdk-linux"
EDIT: Open terminal and type these commands. (yes, on a ternimal , not in bashrc file)
export ANDROID_HOME=~/android-sdk-macosx
PATH=$PATH:$ANDROID_HOME/tools
PATH=$PATH:$ANDROID_HOME/platform-tools
and then in the same terminal just type android
. If configured you would be able to use build commands from this terminal. (it's a temporary solution)
You only have to edit your profile file like this:
sudo su
vim ~/.profile
and put this at the end of the file:
export ANDROID_HOME=/home/(user name)/Android/Sdk
export PATH=$PATH:/tools
export PATH=$PATH:/platform-tools
Save and close the file and do:
cd ~
source .profile
now if you do:
echo $ANDROID_HOME
it should show you something like this:
/home/(user name)/Android/Sdk
I had this problem when running sudo ionic run android
as root as these environmental variables were not persisted. Fixed by running sudo -E ionic run android
.
into ~/.bash_profile add:
export ANDROID_HOME="/path/to/android-sdk-macosx"
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
and then execute it in terminal to take effect immediately;
into /etc/sudoers add: (you can use console: sudo visudo
)
Defaults env_keep += "ANDROID_HOME"
since the building process has to start with sudo
and Node's process.env
get the respective variables.
Download the android SDK http://developer.android.com/sdk/installing/index.html
You only export the path of SDK folder.
export ANDROID_HOME="YOUR_PATH/sdk/"
The procedure is already well explained in the above answers. But if add the ANDROID_HOME
and PATH
to the .bashrc
or .zshrc
present in /home/username/
and try to run the ionic
command with sudo
, you may get this error again.
The reason is, it may look for the ANDROID_HOME
and PATH
in the .zshrc
file of root user instead of currently logged in user. So you shouldn't do that unless you add that in root user's .bashrc
or .zshrc
files.