[Solved] Failed to find ‘ANDROID_HOME’ environment variable

I am trying to build an ionic-android project and i have android sdk installed.

SDK manager installed packages

The name of my project is myApp.I have successfully added android platform to myApp. But when i tries to build the project

~/myApp$ sudo ionic build android

result is

Running command: /home/hari/myApp/hooks/after_prepare/010_add_platform_class.js /home/hari/myApp
  add to body class: platform-android
  ERROR building one of the platforms: 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.
You may not have the required environment or OS to build this project
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.

see the ANDROID_HOME and PATH variable


echo $PATH

I have seen almost the same kind of questions on stack overflow, but none works for me. Is there anything wrong with my android-sdk configuration? How can i build this project?

Solution #1:

You may want to confirm that your development environment has been set correctly.

Quoting from

Set up the Android development environment

Before you can build Android applications, you must install the
Android SDK. Installing the Android SDK also installs the AVD Manager,
a graphical user interface for creating and managing Android Virtual
Devices (AVDs).

  1. From the Android web site, download the
    correct version of the Android SDK for your operating system.

  2. Unzip the archive to a location of your choosing. For example, on Linux or Mac, you can place it in the root of your user directory. See
    the Android

    web site for additional installation details.

  3. Configure the ANDROID_HOME environment variable based on the location of the Android SDK. Additionally, consider adding
    ANDROID_HOME/tools, and ANDROID_HOME/platform-tools to your PATH.

Mac OS X

export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools


export ANDROID_HOME=/<installation location>/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools


set ANDROID_HOME=C:<installation location>android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%	ools;%ANDROID_HOME%platform-tools

The Android SDK download does not include specific Android platforms.
To run the code in this guide, you need to download and install the
latest SDK platform. You do this by using the Android SDK and AVD
Manager that you installed in the previous section.

  1. Open the Android SDK Manager window:


    Note: If this command does not open the Android SDK Manager,
    then your path is not configured correctly.

  2. Select the Tools checkbox.

  3. Select the checkbox for the latest Android SDK.

  4. From the Extras folder, select the checkbox for the Android Support Library.

  5. Click the Install packages… button to complete the download and installation.

    Note: You may want to install all the available updates, but be
    aware it will take longer, as each API level is a large download.

Respondent: Brad W

Solution #2:

In Linux

First of all set ANDROID_HOME in .bashrc file

Run command

sudo gedit ~/.bashrc

set andoid sdk path where you have installed

export ANDROID_HOME=/opt/android-sdk-linux 
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

to reload file run command

source ~/.bashrc

Now check installed platform, run command

ionic platform


Installed platforms:
  android 6.0.0
Available platforms: 
  amazon-fireos ~3.6.3 (deprecated)
  blackberry10 ~3.8.0
  browser ~4.1.0
  firefoxos ~3.6.3
  ubuntu ~4.3.4
  webos ~3.7.0

if android already installed then need to remove and install again

ionic platform rm android
ionic platform add android

If not installed already please add android platform

ionic platform add android

Please make sure you have added android platform without sudo command

if you still getting error in adding android platfrom like following

Error: EACCES: permission denied, open ‘/home/ubuntu/.cordova/lib/npm_cache/cordova-android/6.0.0/package/package.json’

Please go to /home/ubuntu/ and remove .cordova folder from there

cd /home/ubuntu/
sudo rm -r .cordova

Now run following command again

ionic platform add android

after adding platform successfully you will be able to build andoid in ionic.


Respondent: Dineshaws

Solution #3:

These are the steps that you need to follow to successfully set up your Ionic Project to work with android emulator:

  1. Create an Ionic Project: ionic start appName tabs (for tab theme)
  2. cd appName
  3. ionic setup sass
  4. To start the app on web: ionic serve

To add android platform:

Priori Things

First you need to setup the environment variables. For this you need to consider 3 files:

1. ~/.profile (For setting up the variables every time terminal opens or computer boots up):

//Code that you need to append at the last

set PATH so it includes user's private bin directories
export ANDROID_HOME='/home/<user_name>/Android/Sdk' <Path to android SDK>
export PATH=$PATH:$ANDROID_HOME/platform-tools

2. /etc/environment (to set the environment variables):

//All the content of the file

ANDROID_HOME="/home/<user_name>/Android/Sdk" <Path to android SDK>

3. /etc/profile:

//Code that you need to add at the last

JAVA_HOME=/usr/lib/jvm/java-8-oracle <Path where Java is installed>
export JAVA_HOME
export JRE_HOME
export PATH

For loading the above changes made to the file you need to run the following command:

source ~/.profile
source /etc/environment
source /etc/profile

Posteori Things

1. Add platform: ionic platform add android (Note that you need to run this command without sudo)

2. If you are still getting error in the above command then do the following: (here appName = helloWorld)

    cd ..
    sudo chmod -R 777 helloWorld
    cd helloWorld 
    ionic platform add android
    If you are still getting the error then remove ".cordova" folder from the home directory of your PC.

3. To run the app in your android emulator: ionic run android


Respondent: Nikhil Arora

Solution #4:

For those having a portable SDK edition on windows, simply add the 2 following path to your system.


This worked for me.

Respondent: BoCyrill

Solution #5:

I had this issue before.
You need to add sdks ools and sdksuild-tools to your environment path.

Solution #6:

April 11, 2019

None of the answers above solved my problem so I wanted to include a current solution (as of April 2019) for people using Ubuntu 18.04. This is how I solved the question above…

  1. I installed the Android SDK from the website, and put it in this folder: /usr/lib/Android/
  2. Search for where the SDK is installed and the version. In my case it was here:


    Note: that I am using version 28.0.3, your version may differ.

  3. Add ANDROID_HOME to the environment path. To do this, open /etc/environment with a text editor:

    sudo nano /etc/environment

    Add a line for ANDROID_HOME for your specific version and path. In my case it was:


  4. Finally, source the updated environment with: source /etc/environment

    Confirm this by trying: echo $ANDROID_HOME in the terminal. You should get the path of your newly created variable.

    One additionally note about sourcing, I did have to restart my computer for the VScode terminal to recognize my changes. After the restart, the environment was set and I haven’t had any issues since.

Respondent: bsheps

Solution #7:

Execute: sudo gedit ~/.bashrc add

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


source ~/.bashrc
Respondent: Diego Salguero

Solution #8:

I would like to share an answer that also demonstrates approach using the Android SDK provided by the Ubuntu repository:

Install Android SDK

sudo apt-get install android-sdk

Export environmental variables

export ANDROID_HOME="/usr/lib/android-sdk/"
export PATH="${PATH}:${ANDROID_HOME}tools/:${ANDROID_HOME}platform-tools/"
Respondent: Muhammad Numan

Solution #9:

To set ANDROID_HOME environment on ubuntu 20.04 visit Ubuntu’s snap store and install Android studio and then open

vim $HOME/.bashrc

And set the environment variables as follows:

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

With recent versions of Android studio replace ANDROID_HOME with ANDROID_SDK_ROOT otherwise builds will complain that ANDROID_HOME is deprecated.

Respondent: Hamfri

Solution #10:

Came here from google looking for same issue and wasted 4 hours to figure out what could be wrong. And now I feel really stupid while posting this answer. In my case SDK, JDK, JRE, Ant and everything else was installed and working a day before.

But just one particular project was giving me this issue. This one was under “C:UsersNameDocuments” location

Soon I realized that I was running cmd as normal user, as soon as I choose “Run as Administrator” everything started working.

Tip: Always consider project location carefully!

Respondent: Hitin

Solution #11:

This solved my problem. Add below to your system path



Respondent: PKInd007

Solution #12:

I experienced this issue on windows7 computer: the computer shutdown while ionic serve was running (I’m assuming that was the issue that corrupted everything)

Remove node COMPLETELY and reinstall everything on a fresh node copy

Respondent: DudeOfLayers

Solution #13:

In Windows, If you are running this command from VS code terminal and Even after setting up all the environment variable (, platform-tools, tools) it is not working trying running the same command from external cmd terminal.
In my case even after starting a new VS code terminal, it was not able to take the updated Environment path.

It worked when I ran the same command from Windows cmd.

Respondent: himanshu goyal

Solution #14:

I experienced same issue on MAC catalina 10.15 what you add in .bash_profile is not recognised when you echo it on terminal, it is stored temporarily. It is recommended to use .zprofile for permanent and add all environment variables in it.After trying for 5hours i found out this solution. Hope it will be useful for someone.

 vi .zprofile
 insert(press i)

export ANDROID_HOME=/Users/mypc/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:${PATH}

after adding environment variables press esc
then enter :wq!
try echo $ANDROID_HOME in new tab(it will not be empty) path will be 
Respondent: MKR

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy