vtsimoes
vtsimoes

Reputation: 47

Error to build a android app with cordova

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

Upvotes: 0

Views: 7405

Answers (3)

Homa
Homa

Reputation: 132

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!

Upvotes: 1

NGloom
NGloom

Reputation: 408

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

Upvotes: 5

Sandeep kumar H R
Sandeep kumar H R

Reputation: 107

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

Upvotes: 0

Related Questions