Could not find environment variable ANDROID_HOME

I am trying to create an ion-android project and I have Android-sdk installed.

Installed SDK Manager Packages

My project name is myApp.I have successfully added the android platform for myApp. But when I try to build a project

~/myApp$ sudo ionic build android 

result

 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 variable ANDROID_HOME and PATH

 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 saw almost the same questions about stack overflows, but no one works for me. Is there something wrong with my android-sdk configuration? How can I build this project?

+112
android ionic-framework
Mar 24 '16 at 10:36
source share
11 answers

You might want to confirm that your development environment is configured correctly.

Quote from spring.io :

Android development environment setup

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

  • On the Android website, download the correct version of the Android SDK for your operating system.

  • Unzip the archive to your chosen location. For example, on Linux or Mac, you can put it at the root of your user directory. See the Android Developers website for additional installation information.

  • Set the ANDROID_HOME environment ANDROID_HOME based on the location of the Android SDK. Also, 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 

Linux

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

Window

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

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

  • Open the Android SDK Manager window:

     android 

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

  • Check the Tools box.

  • Check the box for the latest Android SDK .

  • In the Advanced folder, select the check box for the Android Support Library .

  • Click the Install Packages ... button to complete the download and installation.

    Note. . You can install all available updates, but that it will take more time, since each level of the API is a big download.

+163
Mar 24 '16 at 13:21
source share

On linux

First of all, set ANDROID_HOME to the .bashrc file

Run command

 sudo gedit ~/.bashrc 

set the andoid sdk path where you installed

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

to reload the file launch command

 source ~/.bashrc 

Now check the installed platform, run the command

 ionic platform 

Exit

 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 is already installed, you must uninstall and install again and again

 ionic platform rm android ionic platform add android 

If you haven’t already installed, add the Android platform

 ionic platform add android 

Please make sure you add the Android platform without the sudo command

if you still get error when adding android platfrom as below

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 delete the .cordova folder from there

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

Now run the following command again

 ionic platform add android 

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

thank

+34
Dec 14 '16 at 8:16
source share

The following are the steps that you must follow to successfully configure your Ionic project to work with the Android emulator:

  • Create an Ionic Project: tabs for the name of the application for ionic launch (for a tab topic)
  • cd appName
  • ion installation sass
  • To launch the application on the Internet: ion service

To add the Android platform:

Priority things

First you need to set up the environment variables. To do this, you need to consider 3 files:

1. ~ / .profile (to configure variables each time the terminal is opened or when the computer boots up):

// Code to add to the last

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

2./etc/environment (for setting environment variables):

// All file contents

 PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" JAVA_HOME="/usr/lib/jvm/java-8-oracle" ANDROID_HOME="/home/<user_name>/Android/Sdk" <Path to android SDK> 

3./etc / profile

// Code to add on the last

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

To download the above changes to a file, you need to run the following command:

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

Constant events

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

2. If you still get an error in the above command, 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 application in your Android emulator: android ion run

Thank!

+25
Dec 18 '16 at 6:51
source share

For those who have a portable version of the Windows SDK, simply add the following path to your system.

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

It worked for me.

+8
Oct 14 '16 at 5:55
source share

I had this problem before.
You need to add sdks\tools and sdks\build-tools to the path to your environment.

+6
Apr 7 '18 at 9:16
source share

Run: 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 

as well as

 source ~/.bashrc 
+3
Sep 13 '18 at 0:51
source share

April 11, 2019

None of the answers above solved my problem, so I wanted to enable the 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. Find where the SDK and version are installed. 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 be different.

  3. Add ANDROID_HOME to your 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, install the updated environment with: source/etc/environment

    Confirm this by trying: echo $ANDROID_HOME in the terminal. You should get the path to your new variable.

    Another point about finding sources. I had to restart my computer so that the VScode terminal recognized my changes. After rebooting, the environment was installed, and I have not had any problems since.

+2
Apr 11 '19 at 23:52 on
source share

Came here from Google looking for the same problem and spent 4 hours to figure out what might be wrong. And now I feel very stupid when posting this answer. In my case, the SDK, JDK, JRE, Ant, and everything else was installed and worked the day before.

But only one specific project gave me this problem. This item was under "C: \ Users \ Name \ Documents" .

I soon realized that I was launching cmd as a regular user, as soon as I select " Run as administrator ", it all started.

Tip. Always carefully study the location of the project.

+1
Jan 05 '17 at 8:25
source share

I ran into this problem on a Windows 7 computer: shutting down the computer while working with the ion service (I assume this is a problem that damaged everything)

Remove the node FULLY and reinstall everything in the new node copy

0
Dec 18 '16 at 7:39
source share

This solved my problem. Add below to your system path

PATH_TO_android \ platforms

PATH_TO_android \ platform tools

0
Mar 04 '19 at 6:56
source share

On Windows, if you run this command from the VS code terminal and even after setting up all the environment variables (i.e. tooling tools, platforms, tools), it does not work, trying to run the same command from the external cmd terminal. In my case, even after starting a new terminal with VS code, it could not accept the updated path to the environment.

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

0
Aug 26 '19 at 19:17
source share



All Articles