280

I'm trying to install PhoneGap and I'm getting the following error:

Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.

Error (screenshot)

enter image description here

What do I do to ensure Android is set up correctly for use with Cordova?

Community
  • 1
  • 1
rrvasanth
  • 2,831
  • 3
  • 15
  • 9
  • 2
    ANDROID_HOME is depreciated now use ANDROID_SDK_ROOT. for more info follow this https://stackoverflow.com/a/55508862/6190043 – Saurabh Bhandari Apr 04 '19 at 06:16
  • 2
    @SaurabhBhandari You are saying the opposite (or maybe it only changed recently). `ANDROID_SDK_ROOT` is deprecated and `ANDROID_HOME` is the right way to go. Ref: https://developer.android.com/studio/command-line/variables#envar – Priyansh Garg Oct 19 '22 at 13:57

25 Answers25

413

For Windows:

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

Taken from this installation guide.

hossein sedighian
  • 1,711
  • 1
  • 13
  • 16
mach
  • 8,315
  • 3
  • 33
  • 51
  • 39
    is correct. But just in case it wasnt 100% clear to people like myself, in the cmd window from your c:windows\system32\projectname> directory type the set command above for android_home. Side note when I was working with Android Studio my SDKs by default were installed to the following location: C:\Users\\AppData\Local\Android\android-sdk In short in your cordova directory above type the set ANDROID_HOME=C:\Users\\AppData\Local\Android\android-sdk -- press enter then re-run the cordova platform add android and the package and project will get created. – natur3 Nov 16 '14 at 22:16
  • 1
    Just setting the ANDROID_HOME does it for me, additionally had to make sure that I had Android 19.0 installed as I tried to add platform to Android project. – Abhijeet Jan 14 '15 at 03:59
  • 28
    To set ANDROID_HOME permanently Right click on My Computer>Properties>Advanced System Settings>Environment variables > 1. Add system variable name = "ANDROID_HOME" value = "E:\Users\user\AppData\Local\Android\sdk" (Enter your android sdk path here) 2. Above system varialbe you can see your PATH, Edit PATH "%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools" save – Dibish Apr 02 '15 at 03:33
  • 2
    You may need to get new CMD after setting the ANT_HOME – Ruwantha May 13 '16 at 22:41
  • 1
    @Dibish this worked for me. If adding from the GUI, make sure to add the Environment Variables to the System Variables and not the User Variables. – peteb Dec 31 '16 at 20:11
  • How to check if the ANDROID_HOME path is correct by a command prompt? – TipVisor Apr 13 '20 at 04:34
  • @TipVisor: with the command "set". If you have [grep for windows](http://gnuwin32.sourceforge.net/packages/grep.htm) your command can be "set | grep -i android_home" to see only one line (is set) or nothing (not set). – Fil Dec 09 '21 at 20:48
  • 8 years later and this is still helpful – Mizile Jun 22 '22 at 14:16
  • I didn't have "tools" folder; searching online, I found that is deprecated. To fix, from Adroid Studio -> sdk manager -> tab "SDK Tools" -> install "Android SDK Command-line Tools (latest)". Now you can replace "%ANDROID_HOME%\tools" with "%ANDROID_HOME%\cmdline-tools". Source: https://developer.android.com/studio/releases/sdk-tools – Claudiu Razlet Mar 05 '23 at 08:52
92

For Mac OS X:

export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
admdrew
  • 3,790
  • 4
  • 27
  • 39
Ankur Tiwari
  • 941
  • 5
  • 4
  • For me my was ~/adt-bundle-mac-x86_64/sdk so the first command was `export ANDROID_HOME=~/adt-bundle-mac-x86_64/sdk`. – Svavar Jan 04 '15 at 12:08
  • 1
    for me: export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/tools/ – AGDM Jan 06 '15 at 17:12
  • Do you need the braces around the 'PATH' as shown above? I'm having a hello of a time getting my hybrid environment set up. But I am new to mac? I had no issues in windows :| but I still love my new mac! – rekordboy Jan 18 '15 at 07:39
  • i did it in Big Sur and using zshenv. but when i close terminals and restart the machine, unable to find saved paths. PATH or ANDROID_HOME or JAVA_HOME – Madhu Velpuri Feb 12 '21 at 16:05
52

I have MAC OS X Yosemite, Android Studio 1.0.1, JDK 1.8, and Cordova 4.1.2

When I tried to add the android project:

cordova platforms add android

I received the message: ANDROID_HOME is not set and "android" command not in your PATH

Based in cforcloud's answer... 'Error: the command "android" failed' using cordova and http://developer.android.com/sdk/installing/index.html?pkg=studio I used the following:

export ANDROID_HOME="/Users/<user_name>/Library/Android/sdk"
export ANDROID_TOOLS="/Users/<user_name>/Library/Android/sdk/tools/"
export ANDROID_PLATFORM_TOOLS="/Users/<user_name>/Library/Android/sdk/platform-tools/"
PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS
echo $PATH

When I tried to create the android project, I received this message:

Creating android project...
/Users/lg/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:126
                    throw e;
                          ^
Error: Please install Android target "android-19".

I ran Android SDK Manager, and installed Android 4.4.2 (API 19) (everything but Glass Development Kit Preview). It worked for me.

===

This is the content of my .bash_profile file.

export PATH=$PATH:/usr/local/bin
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
launchctl setenv STUDIO_JDK /library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk
export ANDROID_HOME="/Users/<UserName>/Library/Android/sdk"
export ANDROID_TOOLS="/Users/<UserName>/Library/Android/sdk/tools"
export ANDROID_PLATFORM_TOOLS="/Users/<UserName>/Library/Android/sdk/platform-tools"
PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS

To edit .bash_profile using Terminal, I use nano. It is easy to understand.

cd
nano .bash_profile

I hope it helps.

Community
  • 1
  • 1
lgm
  • 521
  • 4
  • 5
  • Thanks this also worked for me! But every time I open a new terminal I must set the PATH, is there a way to do set the PATH permanent? – NBoymanns Jan 07 '15 at 08:31
  • Include the PATH in the .bash_profile file. I added instructions in the previous comment. – lgm Jan 09 '15 at 05:11
  • This was very clear and worked for me, much better than all the other answers! I didn't know where I would find the SDK on my system. – WillJones Feb 05 '15 at 22:07
  • @lgm, was it necessary to include the `ANDROID_TOOLS` and `ADROID_PLATFORM_TOOLS`? – Dev Yego Dec 03 '19 at 11:04
38

for windows:

Right click on My computer -> properties -> Advanced system setting -> Environment Variables Edit Path on system variables to ;\yourSdkHome\tools;\yourSdkHome\platform-tools.

Then Close your cmd prompt and reopen.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
hash
  • 5,336
  • 7
  • 36
  • 59
34

On Linux, add this to the end of your .bashrc, .profile or appropriate file for your shell:

export ANDROID_HOME=/home/youruser/whatever/adt-bundle-linux-x86_64-20140702/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools

Please notice that these environment variables will be available for newly created shells, not the already open.

Encompass
  • 562
  • 3
  • 13
  • 27
Quique
  • 909
  • 10
  • 8
  • this worked for me. Your statement "Please notice that these environment variables will be available for newly created shells, not the already open." is what helped me to realize i have to redo this. – jessiPP Jan 02 '15 at 19:36
  • Wouldn't these settings be lost when you reboot? I mean just exporting them this way without actually touching the .bashrc file. – Dev Yego Dec 03 '19 at 11:07
  • As it says above: _add this to the end of your .bashrc, .profile or appropriate file_ – Quique Dec 04 '19 at 12:25
  • For those who are gonna copy this, `platforms-tools` should be `platform-tools`. – roshnet Jul 26 '20 at 11:09
26

Using Android Studio on Windows the system variables settings have changed a little.

You still have to add a system variable ANDROID_HOME, but pointing to the directory containing the android SDK usually installed in C:\Users\YOUR_USERNAME\AppData\Local\Android\android-studio\sdk.

You also need to add the following to the Path system variable:

;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;

Taken from: https://github.com/simnova/webdevdocs/wiki/Installing-PhoneGap-and-Android-Studio-on-Windows

SDK Path also be in C:\Users\USER\AppData\Local\Android\sdk

Rob
  • 26,989
  • 16
  • 82
  • 98
carlosperate
  • 594
  • 4
  • 11
  • you may need to close and reopen AS a few times for this to take affect...for some reason it started working after changing the variables a few times and restarting AS, then back to this solution and it should work..don't give up on this, even for Android Studio v2 – whyoz May 26 '16 at 21:40
11

This is what I just tried to make it work. I was in:

os x Yosemite version 10.10.2
cordova version 4.2.0
android studio 1.0.1
Java SE Development Kit 7

set path:

# on ~/.zshrc file (open a text editor)
export ANDROID_HOME="/Users/<user>/Library/Android/sdk/"
export ANDROID_TOOLS="/Users/<user>/Library/Android/sdk/tools"
export ANDROID_PLATFORM_TOOLS="/Users/<user>/Library/Android/sdk/platform-tools"
PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS

reopen terminal

install "android-19" from android SDK manager

$ android
# pick "SDK Platform Android 4.4.2, API 19"

and then go to a Cordova-based project directory

$ ionic platform add android
kangkyu
  • 5,252
  • 3
  • 34
  • 36
6
Android path set in linux:

$export ANDROID_HOME=/usr/lib/android-sdk-linux
$export PATH=$PATH:$ANDROID_HOME/tools
$export PATH=$PATH:$ANDROID_HOME/platforms-tools

than

$cordova run android
Milap Jethwa
  • 471
  • 4
  • 7
  • I was facing same issue. Problem in my case was I was not running above commands as root user. I executed as root and everything worked fine. – Bhupinder Jul 21 '15 at 06:50
5

In Linux,

edit .bashrc file and add the ANDROID_HOME and PATH variable,

export ANDROID_HOME=/usr/local/android-sdk-linux/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools

After saving .bashrc file, run

source ~/.bashrc

then in type

android in a terminal

if it will run, ANDROID_HOME and PATH is set,

if you get this message,

bash: /src/android-sdk/tools/android: Permission denied

then run

sudo chmod a+x /usr/local/android-sdk-linux/tools/android

otherwise you will get same error message

Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.

NB: Use your android sdk installation path instead of /usr/local/android-sdk-linux/

Mohammed Safeer
  • 20,751
  • 8
  • 75
  • 78
5

For Windows I just had to add an env variable pointing to the SDK folder. Done! (The accepted answer didn´t work for me)

enter image description here

xleon
  • 6,201
  • 3
  • 36
  • 52
5

Only one change was needed to fix the problem:

Go to Start -> Control Panel -> System -> Advanced(tab) -> Environment Variables -> System Variables

set ANDROID_HOME to C:\Program Files (x86)\Android\android-sdk

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
5

ANDROID_HOME is deprecated now instead of using ANDROID_HOME use ANDROID_SDK_ROOT

as per Google android documentation -

ANDROID_SDK_ROOT sets the path to the SDK installation directory. Once set, the value does not typically change, and can be shared by multiple users on the same machine. ANDROID_HOME, which also points to the SDK installation directory, is deprecated.

If you continue to use it, the following rules apply:

  • If ANDROID_HOME is defined and contains a valid SDK installation, its value is used instead of the value in ANDROID_SDK_ROOT.
  • If ANDROID_HOME is not defined, the value in ANDROID_SDK_ROOT is used.
  • If ANDROID_HOME is defined but does not exist or does not contain a valid SDK installation, the value in ANDROID_SDK_ROOT is used instead.

For details follow this Android Documentation link

Saurabh Bhandari
  • 2,438
  • 4
  • 26
  • 33
  • Maybe it only changed recently, but now `ANDROID_SDK_ROOT` is deprecated and `ANDROID_HOME` is the right way to go. Refer to https://developer.android.com/studio/command-line/variables#envar – Priyansh Garg Oct 19 '22 at 14:00
3

I had to close and re-open my windows console (or open a new console), and then open the SDK manager (ran android), after which a bunch of updates and installs had to complete.

maudulus
  • 10,627
  • 10
  • 78
  • 117
3

For those who are working with Ionic Framework on windows and doesn't have andorid studio installed on their PCs, you must have either download Android Studio or at list download the SDK Manager.

If you choose the SDK Manager option you have to set the path for the Enviroment Variable:

  1. Variable name: ANDROID_HOME, Variable value: the path where you installed the android SDK, in my case is, C:\Android\android-sdk.

  2. You have to add the variable to the Path variable system by adding this: ;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;.

  3. Then if you got the "JDK error" just download it from the Oracle website and create a system variable like the Android SDK: Variable name: JAVA_HOME, Variable value: the path where you installed the JDK, in my case is, C:\Program Files\Java\jdk1.8.0_144. Then add it to the Path variable system by adding ;%JAVA_HOME%\bin.

  4. Then if you got the "Gradle error" just fallow the installations steps on the official website of gradle.

  5. Finally you can continue to creating your ionic app's apk.

Note: you have to reopen the cmd window several times or restart your pc after making those changes. Hope this work for you.

Abdelsalam Shahlol
  • 1,621
  • 1
  • 20
  • 31
3

The main reason of this would be the path ( ANDROID_HOME ) is not set in appium. You can confirm that by checking the last step first

step 1 :- Checkout the path where android sdk is located

  1. it could be in c drive/program files or below location mostly

  2.   C:\Users\yourUserName\AppData\Local\Android\Sdk
    

enter image description here

Step2 :- Set the System variables . By typing in search bar in window (you can open this window for setting system variables)

enter image description here

Last step :- To confirm the problem will not repeat verify this, Open appium click on edit configuration and confirm if you can see the path set

enter image description here

Gaurav Khurana
  • 3,423
  • 2
  • 29
  • 38
2

Using Android Studio on Mac, run this on your terminal:

export ANDROID_HOME=/Applications/Android\ Studio.app/sdk/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools

Then, when you type

android

at your terminal, it will run something

Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81
  • I got nothing when I typed android. I can't find and sdk directory under `Android Studio.app`. – huggie Dec 26 '14 at 04:07
  • In my case the Android studio setting (File->Project structure->SDK) points back to ADT bundle (/Applications/adt-bundle-mac-x86_64-20130729/)... – huggie Dec 26 '14 at 04:10
2

It's is mostly with missing andriod SDK. for this issue and "JAVA_HOME" error following solution worked for me... whole day saved after following steps.

To build and run apps, you need to install SDKs for each platform you wish to target. Alternatively, if you are using browser for development you can use browser platform which does not require any platform SDKs.

To check if you satisfy requirements for building the platform:

$ cordova requirements
Requirements check results for android:
Java JDK: installed .
Android SDK: installed
Android target: installed android-19,android-21,android-22,android-23,Google Inc.:Google APIs:19,Google Inc.:Google APIs (x86 System Image):19,Google Inc.:Google APIs:23
Gradle: installed

Requirements check results for ios:
Apple OS X: not installed
Cordova tooling for iOS requires Apple OS X
Error: Some of requirements check failed
BEJGAM SHIVA PRASAD
  • 2,181
  • 1
  • 18
  • 27
2
  1. Go to system properties.
  2. Click change setting.
  3. Click advance tab.
  4. Click Environment Variables button.
  5. In system variables area click new button.
  6. Set ANDROID_HOME in the Variable name field.
  7. Set C:\Program Files (x86)\Android\android-sdk in the Variable value field.
  8. Click ok button.
  9. Double click Path variable in the list.
  10. Click new button.
  11. Past C:\Program Files (x86)\Android\android-sdk\platform-tools in the filed.
  12. Click new button again.
  13. Past C:\Program Files (x86)\Android\android-sdk\tools in the field.
  14. Press enter 3 times.

That's all you need to do.

Abdelsalam Shahlol
  • 1,621
  • 1
  • 20
  • 31
Awais Jameel
  • 1,838
  • 19
  • 14
2

You just need to type a command in flutter_console.bat type flutter config --android-sdk <path-to-your-android-sdk-path>

Vivek Barai
  • 1,338
  • 13
  • 26
1

By the way, one other possibility is that you do have a too old version of cordova android platform.

Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.

Then:

cordova platform update android --save
ch271828n
  • 15,854
  • 5
  • 53
  • 88
0

if Linux users still have the same error, probably they have used "sudo" for adding android platform.. a quick solution for this here, or you have installed cordova using sudo, also there is a solution for this problem here.

Hope this help!

Community
  • 1
  • 1
molhamaleh
  • 353
  • 3
  • 9
0

I also faced this same issue for flutter project and this may work with you too, I got a solution with this.

I did the following steps :

  1. Open system properties
  2. Environment variables
  3. create a new system variable
  4. name: ANDROID_HOME
  5. value: copy your SDK path( Ex: my SDK path E:\SoftWares\Android-SDK)

close your current cmd, and restart it run flutter doctor

this should work on windows

Ramesh kumar
  • 935
  • 14
  • 16
0

I encountered this error and I had to set the ANDROID_HOME using bash_profile.

Then run the source ~/.bash_profile before running appium from terminal.

Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
0

You can set the ANDROID_HOME variable from inside Visual Studio as well:

Go to Tools->Options->Cross Platform->C++ and enter the path under Android SDK.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Babak
  • 1,274
  • 15
  • 18
-1

If nothing else works, make sure that you have correct permissions and ownership set up during building. A quick fix can be:

sudo chown -R <you>:<your_group> *
sudo chmod -R 755 *
Aman Gautam
  • 3,549
  • 2
  • 21
  • 25