52

I just updated cordova + ionic in my app, after that i installed successfully Android-SDK v22 via Android SDK manager.

But after the running command:

cordova build android 

I always get the following message:

Running command: /Users/peter/workspace/myapp/platforms/android/cordova/build 
[Error: Please install Android target: "android-21".

Hint: Open the SDK manager by running: /Users/peter/adt-bundle-mac/sdk/tools/android
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: /Users/peter/workspace/myapp/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /Users/peter/workspace/myapp/platforms/android/cordova/build: Command failed with exit code 2
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1008:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1080:5)

I tried also

cordova platform rm android 
cordova platform add android 

But with the same result:

I tried to find a few hours any working solution, but with luck.

Thanks for any advice.

System information:

OS: Mac OS X Yosemite
Node Version: v0.12.0
Cordova CLI: 4.3.0
Ionic Version: 0.9.27
Ionic CLI Version: 1.3.18
Xcode version: Xcode 6.2 Build version 6C131e 
ios-sim version: 3.1.1 
ios-deploy version: 1.4.0 
redrom
  • 11,502
  • 31
  • 157
  • 264

9 Answers9

114

I just had the same problem. I had to change the target:

# Project target.
target=android-22

This should be done in two files:

myApp/platforms/android/project.properties myApp/platforms/android/CordovaLib/project.properties

Also the manifest should be updated:

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />
Sebastian G. Marinescu
  • 2,374
  • 1
  • 22
  • 33
  • 2
    This is the correct answer. Just want to add this: even though in project.properties, it says everything will be overridden blah blah, just edit it and it will work. – haipham23 Sep 01 '15 at 05:49
  • 1
    I wrote "android" on command line to see my installed version which is 23, so I changed 22 in these files to 23 – Caner Sep 02 '15 at 19:07
  • i have all these settings but still getting the same error message. what exactly do i need to change in those files ? – Mostafa Oct 15 '15 at 01:00
  • Which Android-Version have you installed in your SDK? If you have another version installed than *22*, you have to edit the files correspondingly. – Sebastian G. Marinescu Oct 15 '15 at 10:23
  • See the name of plateform in `C:\Program Files (x86)\Android\android-sdk\platforms`. – user2226755 Oct 18 '15 at 15:33
26

Follow these steps.
1) Type android on command line.(Make sure ANDROID_HOME and PATH are set properly)
2) Select API 21 from the populated list.
3) Click install packages.
4) Type android avd on command line.
5) Set API level and other config.
6) Now type ionic build android.

d-_-b
  • 21,536
  • 40
  • 150
  • 256
Shamsher
  • 1,761
  • 4
  • 21
  • 30
10

many times the problem is that not is configurated the path environment variable ANDRIOD_HOME. Take a look

%ANDROID_HOME% = C:\Program Files (x86)\Android\android-sdk
In Path:
%ANDROID_HOME%\tools;
%ANDROID_HOME%\platform-tools;
fede beron
  • 101
  • 1
  • 4
3

In my case it was the path to my SDK folder that was causing this error.

C:\Users\username\AppData\Local\Android\android-sdk

changed to

C:\Users\username\AppData\Local\Android\sdk

1

I have been having the same problem in windows. It appeared that when I was running the SDK Manager you have to select "Run as Administrator" otherwise it denies permission to install certain files, on of them being "ANDROID-22"

Here is the the link I found to resolve this issue: android sdk manger not updating

Community
  • 1
  • 1
gtrfrost
  • 11
  • 2
1

Open Android SDK Manager, and check whether the target version exists, Install if not exists.

Anoop Pete
  • 492
  • 2
  • 4
  • 17
0

Make sure your project path doesn't consist spaces.

I face the same problem asking me to install the target android platform when build. I have triple confirm my android sdk path, jdk path and various setting in path but still getting the same error. Finally, the problem resolved by simply renamed(removed spaces) the folder that store my Cordova project. For example : "C:\Cordova & Phonegap Sample\MyCordovaApp" to "C:\Cordova_Sample\MyCordova".

Adalard
  • 3
  • 2
0

another way to fulfill an android target requirement would be:

$sdkmanager "platforms;android-21"
woodz
  • 737
  • 6
  • 13
0

For those who run Visual Studio and have Mobile Development with JavaScript installed, you can run C:\ProgramData\Microsoft\AndroidSDK\25\tools\android.BAT and then proceed to install Android 5.0.1 or the relevant API.

enter image description here

gyosifov
  • 3,193
  • 4
  • 25
  • 41