0

I've had this problem when build a android app with cordova command:

cordova build android

D:\Desenvolvimento\ionicapps\AppBelle>cordova build android Running command: "C:\Program Files\nodejs\node.exe" 
D:\Desenvolvimento\ionicapps \AppBelle\hooks\after_prepare\010_add_platform_class.js D:\Desenvolvimento\ionic apps\AppBelle add to body class: platform-android 
Running command: "C:\Program Files\nodejs\node.exe" D:\Desenvolvimento\ionicapps \AppBelle\hooks\after_prepare\020_remove_sass_from_platforms.js D:\Desenvolvimen to\ionicapps\AppBelle 
Running command: D:\Desenvolvimento\ionicapps\AppBelle\platforms\android\cordova \build.bat [Error: Android SDK not found. Make sure that it is installed. If it is not at t he default location, set the ANDROID_HOME environment variable.] 
ERROR building one of the platforms: 
Error: D:\Desenvolvimento\ionicapps\AppBell e\platforms\android\cordova\build.bat: Command failed with exit code 2 You may not have the required environment or OS to build this project 
Error: D:\Desenvolvimento\ionicapps\AppBelle\platforms\android\cordova\build.bat : Command failed with exit code 2 at ChildProcess.whenDone (C:\Users\Victor\AppData\Roaming\npm\node_modules\c ordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23) at ChildProcess.emit (events.js:98:17) at maybeClose (child_process.js:756:16) at Process.ChildProcess._handle.onexit (child_process.js:823:5)

D:\Desenvolvimento\ionicapps\AppBelle>echo %ANDROID_HOME% C:\Users\Victor\AppData\Local\Android\sdk\

Above I show location of env var ANDROID_HOME . I don't know what to do.

Help me, please.

Thanks

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
vtsimoes
  • 47
  • 1
  • 6
  • Look at this and next time you should bother to format your posting... http://stackoverflow.com/questions/26356359/error-android-home-is-not-set-and-android-command-not-in-your-path-you-must-ful – Sithys Mar 23 '15 at 14:16

3 Answers3

5

I'm learning Ionic (based on Cordova) these days, and I came to this similar problems in Mac os too when execute ionic build android, with similar error msg below:

Running command:/Users/ngloom/code/workspace/myWork/platforms/android/cordova/build

[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.]

and the msg still exist after i setting the ANDROID_HOME environment, upgrade the sdk tools, finally i have to look into the check_reqs.js which throw the error and i found that the js is based on the cmd output by android list targets, and finally I found the android is owned by root (very likely that the android is installed by sudo brew before) and only error returned when executing by my user.

So I change the owner of android and everything works !

I post my solution here as a solution backup, hoping to help the guys in case like me :)

Community
  • 1
  • 1
NGloom
  • 408
  • 7
  • 13
1

Unfortunately this can be a bug caused by upgrading android SDK versions. In general look for for different reasons:

  1. First if you have to set the ANDROID_HOME environment variable. (according to your OS - In windows , right click your PC icon "MY PC", --> properties -> Advanced system settings -> Environment Variables" and set ANDROID_HOME variable and edit PATH variable to your path to your android SDK, tools & platform tools.

  2. Secound try the "android" command in command tool, if android sdk couldn't open it cause a problem to build your app. I got this error:

    The "android" command is no longer available. For manual SDK and AVD management, please use Android Studio. For command-line tools, use tools\bin\sdkmanager.bat and tools\bin\avdmanager.bat

to solve it, you should downgrade your sdk using this links: (Mac) https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip (Windows) https://dl.google.com/android/repository/tools_r25.2.3-windows.zip

and replace the zip file with your "tools" folder in your android SDK, It will work fine after trying "android" command and building app command in cordova and ionic frameworks.


Digging the reason: (In my case)

Why failing android command is causing this problem?

part of the cordova or ionic configuration in js files are using android command to "VERIFY" your "ANDROID_HOME" and "PATH" environment variables to operate building your app, and in case of any failure accessing to Android sdk via command access, system tells you "Android SDK" is not found. Recently, in new version android command is no longer accessible and is causing issues for any operation whom used this command. :/

Hope it works for you, It took a time for me to figure out solving this issue and don't forget to (+1) if it helped you!

Homa
  • 134
  • 1
  • 6
  • Downgrading the SDK tools worked for me. I already had all of the path variables set. I hope Ionic gets updated to support building from the latest sdk tools. – Luke Apr 24 '17 at 08:44
  • apparently, as "android" command access is removed by Android studio recently, it caused malfunctioning in previous products whom have used this command. Maybe Android studio should revert it's access instead. – Homa May 03 '17 at 05:54
0

Setting environmental variables use this to set up the path to tools and platform tools and update SDK for the android version that you are trying to build and make sure weather its Ionic or cordova application and then try once

  • I'm using windows 8. And I setup environmental variables before. But the problem persist. I try to use ionic, but not function too, and any give me any response, because of this I try to use Cordova command, and the I get this error. – vtsimoes Mar 23 '15 at 14:35
  • Could be that you did that, but like you see there is sth incorrect with your path. – Sithys Mar 23 '15 at 14:42
  • @vtsimoes their are few set ups which had to be done for proper working ... so http://stackoverflow.com/a/26825450/4195629 set the path for environment and everything will be fine. Make use of the comment from sithys that question has most of the answers you are seeking. – Sandeep kumar H R Mar 23 '15 at 14:43
  • @Sithys path that i have mentioned is to make you understand that its windows OS(dir's - D:\ ) – Sandeep kumar H R Mar 23 '15 at 14:44
  • My echo %PATH% give me correct path to Android SDK, but error persist. Echo %ANDROID_HOME% gives too the correct path. – vtsimoes Mar 23 '15 at 14:57
  • The problem is platform for android is already their but the required API level & its specific SDK is not their so you can open eclipse/AndroidStudio and update the SDK `D:\Desenvolvimento\ionicapps\AppBelle\platforms\android\cordova \build.bat [Error: Android SDK not found. Make sure that it is installed. If it is not at t he default location, set the ANDROID_HOME environment variable.]` its given their ... http://stackoverflow.com/questions/25738692/not-able-to-create-avd-in-android-studio here you can getta know the way we can update the SDk – Sandeep kumar H R Mar 23 '15 at 15:04
  • Go through this, you will get a good understanding 1.http://cordova.apache.org/docs/en/4.0.0/guide_cli_index.md.html#The%20Command-Line%20Interface 2.http://cordova.apache.org/docs/en/4.0.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide – Sandeep kumar H R Mar 23 '15 at 15:11