Ionic build android throws error

I am trying to create a simple app through ionic framework. I have followed all the instructions given in the link and installed node.js, Ionic and Cordova frameworks, Apache Ant, Java SDK and Android ADK. Then I start an app, go to its folder, add android platform and build it. In the command ‘ionic build android’, it gives the below error:

[Error: Please install Android target: "android-21".

Hint: Open the SDK manager by running: C:\Users\Aparna\AppData\Local\Android\and
You will require:
1. "SDK Platform" for android-21
2. "Android SDK Platform-tools (latest)
3. "Android SDK Build-tools" (latest)]
ERROR building one of the platforms: Error: C:\Windows\System32\myApp\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: C:\Windows\System32\myApp\platforms\android\cordova\build.bat: Command failed with exit code 2
    at ChildProcess.whenDone (C:\Users\Aparna\AppData\Roaming\npm\node_modules\c
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

I have verified that all the packages mentioned in the error are installed, and also updated the path variables correctly. However, I still keep getting the same error.

Can anyone suggest a solution/ workaround?

You can try building after closing all other applications except your terminal… Some times this problem occurs due to low memory availability required by Android build.
Please let me know if it solves ur problem.

Thanks for the suggestion!

However, I restarted my PC, and opened just the terminal and executed the build command. It would still throw me the same error.

Am I missing something here?

I think you do not have latest android sdk : android-21 , you can update sdk using “Manage Sdk.exe” . In windows search "Manage Sdk: and then update your android sdk to latest.

Did you follow this link ? Android Platform Guide
And setup environment variable ANDROID_SDK_HOME ?

@rajul885 I did check and all the packages for Android API 21 are installed. Also I have installed the latest Android SDK Platform-tools and Build-tools. Below is a screenshot for your reference:

Still not sure what is causing the error.

@helsen Yes i did add both the Android SDK platform-tools and tools as environment variable and to the PATH variable.

@aparnarao If you run:

ant -version

in your command line, what you see?

If ant it’s ok,

try this Please install Android target: “android-21”

Thanks @helsen for the post. ant is working fine on my PC. This is what I get when I execute the command ant -version

Apache Ant(TM) version 1.9.4 compiled on April 29 2014

However, i will try to make changes according to the link you have provided and will update you if I am successful.

Go to yourPathApp/platforms/android, then edit the AndroidManifest.xml when you find

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="21" />

but instead of 21 write 19.
In the same folder, there is the file; edit it when you find


always with 19.


This worked for me, found this solution on Stackoverflow.

Thanks @veshsare for the solution!
However, when I tried to update the AndroidManifest.xml and, it gave me an access denied message and wouldn’t let me update. One of the reasons might be, I was running the command prompt as an Admin and so the project folder was getting created in C:\Windows\System32. And maybe that is why, ionic as well was not able to access the android libraries.

Finally, I deleted my project folder from System32 (which I was able to do somehow with admin permissions), and then opened up a user command prompt, and created the project in a folder on desktop.

I executed all the commands, and I was successfully able to build the app.

Thanks everyone for your suggestions!