cordova build –release android always picks the highest api level-ThrowExceptions

Exception or error:

I am trying to build my cordova app for android, using ionicframework. I have set my target API level to 16 (I have that installed from Android SDK manager) but it somehow always picks up level 21.

in project/config.xml:

 <preference name="android-targetSdkVersion" value="16"/>

in platforms/android/AndroidManifest.xml, it shows the same:

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

but running cordova build --release android I get:

[getbuildtools] Using latest Build Tools: 22.0.0
     [echo] Resolving Build Target for OpsVedaMobile...
[gettarget] Project Target:   Android 5.0.1
[gettarget] API level:        21

I suspect I am missing some more settings, will appreciate help. I used the how-to from this ionic doc

ionic: 1.0.0.rc-5, ionic CLI: 1.3.22, cordova: 5.0.0, node: 0.10.36 – on Windows7


it appears that the target level didn’t matter at all. I now wonder how/where does it become significant.

How to solve:

in latest ionic framework you can change the target by changing


and change the 22 into these two files with 16



ion1 = my project base folder


npm install -g cordova 

above command always install latest cordova-android-version and so android-target is latest. So we can solve the above problem by installing appropriate cordova version.

you can install appropriate version of cordova using this command npm install -g cordova@5.0.0 where 5.0.0 is cordova-android-version.all version of cordova can be viewed using following command.

npm view cordova versions

4.1.X(cordova-android Version) supports 14-22 (API level) and

5.X.X(cordova-android Version) supports 14-23 (API level)


So this bit of xml does two things, sets the minimum api version for the android app, and sets the target, obviously because of their name.

So api 10 is android 2.3, which we’ve dropped support for. So we can bump that to 14, or android 4.0

Api 19 is 4.4 which is all good.

So these number are part of the default project structure that cordova makes. You could create a hook that after the project is add, it changes the default api level to 14 and 19 instead of manually doing it.

But to change it, go to platforms/android/android.xml, if you edit this, you should be good.
Before change:

] android update project –subprojects –path “platforms/android” –target android-19 –library “CordovaLib”

I changed this to:

] android update project –subprojects –path “platforms/android” –target android-14 –library “CordovaLib”

And then modified the AndroidManifest.xml file as you suggested, now all the debug states level 14 and it compiled. I just sent a copy over to my buddy again.. we’ll see if it works!

Leave a Reply

Your email address will not be published. Required fields are marked *