Build Ionic 2 Cordova Apps For Specific Platform Version

In this tutorial, we will take a look at how you can build your app for a specific version of Android and iOS.

Let me start off by saying that you need to have the platform version that you wish to build for installed on your system to be able to build for it. For example, if you wish to build for Android API 16 but you only have Android API 23 in you build tools then you won’t be able to build for API 16. The same goes for iOS.

By default, if you run the build command, your app will be built for the default target for the CLI version of Cordova. For each version of the Cordova CLI the default build target is different. As a result, it becomes necessary to know how you can target the platform version of your choice.

We will be editing the config.xml file which can be found at the root of the project. This file has a lot of configuration that Ionic and Cordova uses to build your app. All the code that will be shown in the tutorial has to be added inside the <widget> tag in config.xml. I will also attach a  sample config.xml file for you to download at the end to the post.

For Android

Android has three values that you can set.

  • First, we can set the minSdkVersion
This will build an app that will be supported by an Android device which has to have Android API-19 KitKat (4.4) installed at the least. This means that devices running latter version of the Android will also be able to run the app. It is a good practice to have a minSdkVersion set.

Here is what minSdkVersion means according to google docs

An integer designating the minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in this attribute. You should always declare this attribute.

  • Similarly, we can set maxSdkVersion as follows
Contrary to minSdkVersion this sets the maxSdkVersion and it will work as you would expect. This preference is optional. You can read more on google docs about maxSdkVersion

  • Lastly, for Android we can also set targetSdkVersion as follows
You can add all the three preference tags for one app, the order of the tags does not matter. Just make sure you are putting the right value of the API in the preference tag.


For iOS

For iOS we need to add only one preference tag.


So the finished config.xml file for Cordova will look as follows



Targeting a specific build platform for Ionic and Cordova is just a matter of adding <preference> tag. I have seen various forum and articles that suggest to make changes to the AndroidManifest.xml file, but that simply will not work, as the AndroidManifest.xml file is a dynamically generated file. It will get overwritten every time you run the build command. One more thing to keep in mind is that make sure to run the build command after making changes to the config.xml file.


For Cordova and Ionic 2 Download Code:

Code Will Be Sent Via Email


Leave Me Your Questions And Feedback

Getting your feedback inspires me the most so hit me up in the comments here or on the comments section on my YouTube Channel or on twitter @uncutAcademy
Consider Subscribing / Donating
Subscribe To Mailing List
If my site was helpful to you, then please consider donating via paypal:
Prantik Vaghela

Prantik Vaghela (uncutAcademy)

Hi my name is Prantik Vaghela. I have done my Bachelors and Masters in Computer Science and am a web developer and now a Tutor through my blog. :-)