Here we will see how you can build your apps using the PhoneGap build for a specific operating system and specific version of the operating system. This post is a part of my Free Phonegap Build beginner course and we will be using the config.xml that we created in one of the tutorials in the course.
By now I assume that you are familiar with the PhoneGap build dashboard and have tried to build apps using it. A thing you might have noticed that whenever you build an app using PhoneGap build it builds for all supported platforms i.e, Android, iOS and windows. This is the default behavior, so how can you make the build process only build for any one platform?
This can be easily achieved by adding
<platform> tag as follows
<platform name="ios" />
<platform name="android" />
<platform name="winphone" />
This will build you app for the platforms that you specify. Note that you can add more that one
Setting Specific Version For PhoneGap apps
Now that we know how we build for specific platforms it’s time we see how we can build for a specific version for that platform. To do that we will need a
<preference> tag. A thing to note is that the value of the preference tag depends on the platform that you wish to target. let’s see a few examples
- First we can set the minSdkVersion
<preference name="android-minSdkVersion" value="19" />
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
<preference name="android-maxSdkVersion" value="15" />
To illustrate how this attribute can affect your application after system updates, consider the following example:
An application declaring
maxSdkVersion="5"in its manifest is published on Google Play. A user whose device is running Android 1.6 (API Level 4) downloads and installs the app. After a few weeks, the user receives an over-the-air system update to Android 2.0 (API Level 5). After the update is installed, the system checks the application’s
maxSdkVersionand successfully re-validates it. The application functions as normal. However, some time later, the device receives another system update, this time to Android 2.0.1 (API Level 6). After the update, the system can no longer re-validate the application because the system’s own API Level (6) is now higher than the maximum supported by the application (5). The system prevents the application from being visible to the user, in effect removing it from the device.
- Lastly for Android we can also set targetSdkVersion as follows
<preference name="android-targetSdkVersion" value="12" />
This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app’s forward-compatibility with the target version. The application is still able to run on older versions
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 we only need to set one preference value i.e,
. It can be set as follows
<preference name="deployment-target" value="7.0" />
Phonegap build currently supports the following windows venison Windows 8.1, Windows phone 8.1, & Windows 10 (using Windows Universal App Platform). As windows has now become an operating system that runs on mobile as well as desktop you can add preference for windows can be set as follows
<!-- Windows 10 (default): -->
<preference name="windows-appx-target" value="uap" />
<!-- Windows 8.1: -->
<preference name="windows-appx-target" value="8.1-win" />
<!-- Windows Phone 8.1: -->
<preference name="windows-appx-target" value="8.1-phone" />
Let’s see a complete example of a config.xml file that builds only for Android and targets Android KitKat and supports a minimum version of Android JellyBean.
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.phonegap.example"
versionCode = "1"
version = "1.0.0" >
<!-- versionCode is Android only -->
<!-- version is in major.minor.patch format -->
<name>PhoneGap Example App</name>
An example for phonegap build app which wont show up in the playstore.
<author href="https://YourWebsite.com" email="yourEmail@goesHere.com">
Name Of The Author
<plugin name="cordova-plugin-x-socialsharing" source="npm" />
Notice here that I am not setting
by doing so the app can be also installed on any newer Android versions as we have not set any upper limit.
If you do not specify any
<preference> tag to target a version of any operating system then the latest version supported by PhoneGap Build service will be used.
Targeting a specific platform during the PhoneGap build build-process will save you some wait time. Targeting a specific version will allow you to fine tune you app build even more in targeting an older version of the operating system or abandoning support for an older version and build for a new one.
Watch Video Tutorial Here: