Android SDK Versions Tutorial With Kotlin

New SDK versions released with each new version of Android provide great new features. In this tutorial we will learn how to utilize them in our apps. By Kevin D Moore.

Leave a rating/review
Download materials
Save for later
Share
Update Note: Kevin Moore updated this tutorial. The original tutorial was
written by Eunice Obugyei and Eric Crawford, who updated it to Kotlin.

Ever since the first release of Android, the range of supported devices has grown to represent a wide array of phones, smart watches, cars, Android Internet of Things and more. Everything necessary to start developing Android apps for those devices falls under one specification called the Android SDK (software development kit). New SDK versions are released with each new version of Android, and that is the focus of this tutorial.

These new SDK versions take advantage of the increased processing power available on the latest devices to provide great new features. Awesome, right? The flip side, of course, is that Android developers face the challenge of making sure an app will work on a range of devices running different versions of the Android SDK.

There are some best practice guidelines and tools to help get the work done without compromising your UX or deadlines.

Note: This Android SDK Versions tutorial assumes you are already familiar with the basics of Android development and Kotlin. If you are completely new to Android development, read Beginning Android Development and our other Android and Kotlin tutorials to familiarize yourself with the basics.

In this Android SDK Versions tutorial, you’ll learn about:

  • Android SDK versions and API Levels
  • Android Support Libraries and their importance
  • How to use the Android Support Library to make an app backward-compatible
  • How to use the CardView Support Library

To put theory into practice, you’ll play with a simple app called Continents. Continents gives short descriptions for all of the continents in the world.

Note: This tutorial requires Android Studio 3.3.2 or later.

Getting Started

Click on the Download Materials button at the top or bottom of this tutorial to get your hands on the starter project for this tutorial and extract the downloaded .zip file to get the project.

Select Open an existing Android Studio project from the Quick Start menu to open the starter project:

If you are on a windows machine you can also select File ▸ Open. Navigate to and select the starter project folder.

Emulating Different SDK Versions

We want to try running the sample app on different Android versions. But it’s unlikely anyone has an Android device for every single API Level of the SDK. So first, let’s learn how to set up emulators with different SDK versions.

To set up an emulator, locate the AVD (Android Virtual Device) Manager on the Android Studio Toolbar.

Creating a Virtual Device

If the Toolbar is not showing, select View ▸ Toolbar to show it. You can also select select Tools ▸ Android ▸ AVD Manager to open the AVD Manager.

Click the Create a virtual device button. That will open the Select Hardware section of the Virtual Device Configuration window.

Select a device of your choice and click Next. That opens the System Image section, which currently shows recommended system images.

The x86 Images tab will list all the x86 emulator images. The Other Images tab will show both ARM and x86 emulator images.

Note: It is recommended to always use x86 images. These will run the fastest on most PC and Mac computers

Downloading a System Image

To download a system image that you do not already have installed, click the Download link by the release name.

Notice that the Android platform currently has twenty five major versions of the SDK. Starting with Android 1.5, major versions of the SDK have been developed under a confectionery-themed code name. Google has managed to choose these code names in an alphabetical order. They haven’t run out of names of sweets yet. :]

Each version (minor or major) of the Android SDK has an integer value that uniquely identifies it. This unique identifier is referred to as the API Level. The higher the API Level, the later the version. For developers, API Level is important because it is what determines the range of devices an app can run on.

Look at an example, the Android 9.0 release. You can see that:

  • It is the most recent version of the Android SDK
  • Its version number is 9.0
  • Its code name is Pie
  • It has an API Level of 28

For this tutorial, you will need at least two emulators, one with API Level 16 and another one with API Level 28.

Going back to the System Image screen in Android Studio, click the Download button for each of the SDK versions you will need for this tutorial that you have not already downloaded (Level 16 and Level 28). Then select the system image for Level 28 and click Next.

On the next screen, click Finish.

Repeat the same steps to set up an emulator with API level 16.

Running the Sample App

Try running the sample app on the emulator running API Level 28:

It all looks great, right? But if you were to try and run the app on a device with API Level lower than 28 it wouldn’t run. This is because the app only runs on devices that run Android API Level 28 and upwards, which isn’t great for older devices. Later, you’ll learn how to extend the app’s support from Android API Level 28 to as low as Android API Level 16.

SDK Versions and API Levels

As mentioned earlier, the API Level is a unique integer that identifies a specific version of the Android SDK. Take a look at how to specify API Levels in Android Studio to compile and release an app.

Open build.gradle for the app module:

Here, you can see three important attributes:

  • minSdkVersion is the minimum API Level with which the app is compatible. The Android system will prevent a user from installing the app if the system’s API Level is lower than the value specified in this attribute. Android requires the minSdkVersion attribute to always be set.
  • targetSdkVersion is the API Level that the app targets. This attribute informs the system that you have tested against the target version. The targetSdkVersion defaults to the minSdkVersion if not specified.
  • compileSdkVersion specifies the API Level to compile the app against.

These attributes can be adjusted in the app modules build.gradle file.

Note on SDK previews: It’s important to know that when you set the compileSdkVersion to a preview release of the Android framework, Android Studio will force the minSdkVersion and targetSdkVersion to equal the exact same string as compileSdkVersion. This policy is necessary to prevent situations wherein you might upload your app to the Google Play Store. As a result, you can only run apps where compileSdkVersion is set to a preview release on emulators with that exact same preview and you won’t be able to run it on older devices.