Xamarin Android - Platform Version Support

So version support and Android is confusing.  Let’s just get the straight.  In writing this post I have read things over multiple times.  Do not get discouraged.  Google generally gives three names to the API levels: an API number/integer, a version number and a candy name.  This is documented on their platform dashboard.  For example KitKat API 19, Version 4.4.

While working with Xamarin Android, project properties show the following selections.  We have Compile using version, Minimum Android to target and Target Android version. Ugh.

image

These values are pushed to the AndroidManifest.xml which is included in your project.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="DrawerLayout_V7_Tutorial.DrawerLayout_V7_Tutorial">
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />
    <application android:label="DrawerLayout_V7_Tutorial"></application>
</manifest>

While the latest versions of Android often provide great APIs for your app, you should/need to continue to support older versions of Android until devices get updated.

The Android Platform Versions page has details of version and respective codename/API level.  Also of interest is the distribution % for each version.  At the time of this post, interestingly KitKat version 4.4 (API 19) has the largest distribution. 

In order to use several recent platform API’s on an older version device/platform Android/Xamarin provide what is called support libraries.  The Android Support Library package is a set of code libraries that provide backward-compatible versions of Android framework APIs as well as features that are only available through the library APIs.  Each support library is backward-compatible to a specific Android API level.  This means that your application can use the libraries features and still be compatible with devices running older API levels.  These support libraries are included in your project and help your application run efficiently on older platforms.  Support Libraries each target a base Android API level and each provides a different set of features. In order to effectively use the libraries, it is important to consider what features you want to support and understand what features are supported by each library at what Android API level.

Based on Android Support Library Features  - In general, we recommend including the v4 support and v7 appcompat libraries, because they support a wide range of Android versions and provide APIs for recommended user interface patterns.

In a recent blog post I am working with ActionBars and Toolbars.  I can see v7 appcompat library adds support for the ActionBar user interface design patter.  v7 appcompat also includes support for material design implementations.  Now looking at the Toolbar is implemented in API level 21 or higher.  I do want my code to run on KitKat (version 4.4) API level 19.  Toolbar minimum is API 21 which is version 5 (Lollipop).  So how do I setup my above minSdkVersion and targetSdkVersion?

Compile using Android version: Set to the version that has all the features you need.

Minimum Android to Target – android:minSdkVersion : Specifies the minimum API Level on which the application is able to run. The default value is "1".  Note: 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.  Set to the lowest version you want to support.

Target Android version
- android:targetSdkVersion : To allow your app to take advantage of these changes and ensure that your app fits the style of each user's device, you should set the targetSdkVersion value to match the latest Android version available (If not set, the default value equals that given to minSdkVersion).  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 (down to minSdkVersion).  This does get a little confusing but bottom line To maintain your application along with each Android release, you should increase the value of this attribute to match the latest API level, then thoroughly test your application on the corresponding platform version.  Stack Overflow had a good definition:  With this attribute set, the application says that it is able to run on older versions (down to minSdkVersion), but was explicitly tested to work with the version specified here. Specifying this target version allows the platform to disable compatibility settings that are not required for the target version (which may otherwise be turned on in order to maintain forward-compatibility) or enable newer features that are not available to older applications. This does not mean that you can program different features for different versions of the platform—it simply informs the platform that you have tested against the target version and the platform should not perform any extra work to maintain forward-compatibility with the target version. Set to Use Compile using SDK version.

image
Note: In Xamarin Studio the above choices appear slightly different.  Within XS, Project Options – General shows Target framework, then also Project Options – Android Application (2nd screen shot below)

image

image

Target framework: Compile using Android version
Minimum Android version: is the same as Minimum Android to target
Target Android version:is the same as Target Android version

Author

david

comments powered by Disqus

Categories

Recent Tweets

"Setting up and Getting Started with Power BI Embedded | Data Exposed" channel9.msdn.com/Shows/Data-Exp… #webcast #feedly
Retweeted by @dyardy @scottgu @victoriabeckham Worlds collide, double take on that photo!
@scottgu @victoriabeckham Worlds collide, double take on that photo!
@projectedxyz It is really easy, what are you doing (isn't this data which on the web)