Ionic android build Error - Failed to find 'ANDROID_HOME' environment variable
For OSX
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'sprocess.env
get the respective variables.
Setup for Linux/Ubuntu/Mint
- download Android Studio or SDK only
- install
- set PATH
3.1) Open terminal and edit ~/.bashrc
sudo su
vim ~/.bashrc
3.2) Export ANDROID_HOME and add folders with binaries to your PATH
Common default install folders:
- /root/Android/Sdk
- ~/Android/Sdk
Example .bashrc
export ANDROID_HOME=/root/Android/Sdk
PATH=$PATH:$ANDROID_HOME/tools
PATH=$PATH:$ANDROID_HOME/platform-tools
3.3) Refresh your PATH
source ~/.bashrc
4) Install correct SDK
When
ionic build android
still fails it could be because of wrong sdk version. To install correct versions and images runandroid
from command line. Since it is now in your PATH you should be able to run it from anywhere.
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)
Case: using SO Windows, try:
set ANDROID_HOME=C:\\android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
more in: http://spring.io/guides/gs/android/
Case: you don't have platform-tools:
cordova platforms list
cordova platforms add <Your_platform, example: Android>