I’m currently getting up to speed with iOS, Android (native and Xamarin) and Firefox mobile development. As you can tell from my blog, I am still very much in love with Windows Phone, but would like to stay abreast with other mobile platforms as well. With that said, one thing that confused me when working with Android is all of the different API versions available. I’ve provided a screenshot below of the different emulators you can start with Xamarin.
The table provided below maps, the API level to OS version and name. (I’ve left off 17 which is JellyBean, because that emulator image is not installed on my machine).
|API Level||OS Version||OS Name|
|10||2.3.3 and 2.3.4||GINGERBREAD_MR1|
|14||4.0, 4.0.1, 4.0.2||ICE CREAM SANDWICH|
|15||4.03, 4.04||ICE CREAM SANDWICH_MR1|
The _MR1 stands for “Maintenance Release”. You will probably notice that anything under version 7 of the API is not included. You can still download the image, but very few users are using those older devices. It also skips the non-maintenance release images (ex. 9, 11, 13). You don’t need them on your system if you have the _MR1 as it includes everything in the previous version. More in-depth info can be found here.
The Manifest File
In Windows Phone, we have the WMAppManifest.xml. In Android, we have the AndroidManifest.xml. Both of these files are similar in nature in that they describe certain aspects of your projects. Relating to the various Android API levels, you can specify the minimum API level as well as the target API level.
The minimum API Level is the lowest API that the application will run on. If you are using Xamarin.Android for Visual Studio 2012, you can select the project properties and set it under the “Application” tab. One thing to note is that it list the “Minimum Android to target” instead of the API Level. If you look back at my chart, then you will see this maps to API 8.
The target API Level specifies the API Level on which the application is designed to run. In some cases, this allows the application to use manifest elements or behaviors defined in the target API Level, rather than being restricted to using only those defined for the minimum API Level. This can be set in the “Android Manifest” page in the project properties in Visual Studio 2012 as shown below. This time it provides the API level to select from.
Note: A AndroidManifest.xml file is created automatically for you using Xamarin. Upon first click of this tab, you will need to create one if you want to customize this.
Taking a look at the Completed Android Package File.
Once compiled, you will find the apk file in the “bin” folder as shown below. One is signed and the other is not. Make a copy of the unsigned one and rename it to .zip to view the contents.
Here is the contents of the hello.world.apk. We are only interested in the AndroidManifest.xml file, so you can ignore the others for now.
If we try to open the AndroidManifest.xml in notepad, then we obviously can’t read it with the naked eye:
This is where we can make use of a tool supplied by Android called aapt.exe (Android Asset Packaging Tool) found in the C:\Users\<Your User Name>\AppData\Local\Android\android-sdk\platform-tools folder.
Simply run this command in a command prompt with the .apk file copied to this directory. An example of the command can be found below.
aapt l –a packagename.apk
Scroll down until you find the “uses-sdk” as shown below.
To make things easier to read, I’ve also included it below:
E: uses-sdk (line=3) A: android:minSdkVersion(0x0101020c)=(type 0x10)0x8 A: android:targetSdkVersion(0x01010270)=(type 0x10)0xf
Converting Hexadecimal to Decimal, we can see that the minSdkVersion ends in 0x8 which equals API level 8 and the targetSdkVersion ends in 0xf which equals API level 15. This is exactly what how we set those fields earlier.
I hope this helps clear up API version levels in Android as I’ve been curious as to how it works. If you have any questions then feel free to drop me a line below and I’ll be talking about all kinds of mobile development in the future.TweetFollow mbcrump
Last revised: 06 May, 2013 02:39 AM
No new comments are allowed on this post.