Failed to find 'ANDROID_HOME' environment variable

Viewed 354908

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 $ANDROID_HOME
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/hari/Android/Sdk

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/hari/Android/Sdk/tools:/home/hari/Android/Sdk/platform-tools:/usr/local/bin:/opt/gradle/bin

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?

17 Answers

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

F:\ADT_SDK\sdk\platforms
F:\ADT_SDK\sdk\platform-tools

This worked for me.

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:

    /usr/lib/Android/Sdk/build-tools/28.0.3

    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:

    ANDROID_HOME="/usr/lib/Android/Sdk/build-tools/28.0.3"

  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.

Execute: sudo gedit ~/.bashrc add

JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
export PATH
export ANDROID_HOME=~/Android/Sdk 
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

and

source ~/.bashrc

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/"

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.

This solved my problem. Add below to your system path

PATH_TO_android\platforms

PATH_TO_android\platform-tools

In Windows, If you are running this command from VS code terminal and Even after setting up all the environment variable (i.e.build-tools, 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.

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 
printed

Spent almost hours without sleeping searching everything to install apk on my android device for debugging, but couldn't be able to install the apk due to ADP ENONET.

"adb reverse": spawnSync Users/shanu/Library/Android/sdk/platform-tools/adb ENOENT

The solution was very simple, literally, I've added variables into .bash_profile, .zshrc, environment, ~/.profile etc and almost tried every solution but couldn't be able to solve it.

The mistake was minor.

Instead of adding like this (Correct) in my bash_profile file.

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

I was adding something like this which was wrong in my case.

  export ANDROID_HOME=Users/shanu/Library/Android/sdk
  export PATH=$PATH:$ANDROID_HOME/emulator
  export PATH=$PATH:$ANDROID_HOME/tools
  export PATH=$PATH:$ANDROID_HOME/tools/bin
  export PATH=$PATH:$ANDROID_HOME/platform-tools

Might be helpful: Inside package.json add like this for yarn android command

"android": "source ~/.bash_profile&&react-native run-android"

After updating your path and environment variables as recommended in the other answers, sometimes all you need do is simply restart your machine. It took me over 24 hours until I ran out of options and restarted.

I too faced The same issue , I resolved it this way.

Open Terminal

cd to the folder where eclipse.app is located E.g cd /Users/Shared/eclipse/jee-2020-09

Type open Eclipse.app/

Eclipse will now open and will be able to access the system environment variables as well.

Check it using the code:

System.getenv().forEach((k, v) -> {
    System.out.println("ENV : " + k + ":" + v);
});
Related