The Compile SDK, Minimum SDK, and Target SDK Versions
There are three very important parameters you should understand about supporting different versions of Android in your app. Reviewing this information will help you determine what settings to use to support users who are running your app on older versions of Android.
Compile SDK Version
The Compile SDK Version is the version of Android in which you write code. If you choose 5.0, you can write code with all the APIs in version 21. If you choose 2.2, you can write code only with the APIs that are in version 2.2 or earlier. You can’t use the Wi-Fi Direct APIs in version 2.2, for example, because they weren’t introduced until version 4.0.
Minimum SDK Version
Android operating system (OS) versions are backward-compatible. If your minSdkVersion is set to Android version 4.0, for example, your application can run on Android 5.0, 4.4, 4.3, 4.2, 4.1, and 4.0. The benefit of choosing the 4.0 framework is that your application is exposed to a much larger market share. Your app can be installed on devices going back to 4.0 (and on future versions, too!).
Selecting an older version isn’t free of consequences, however. By targeting an older framework, you’re limiting the functionality you have access to.
You should set the minSdkVersion to the oldest version of Android that you are willing to support. For this app you will simplify your development life by supporting only the latest version of Android.
If your Minimum SDK Version is not the same as your Compile SDK Version, you must take great care! For example, you might set your Compile SDK Version to 5.0 in order to use the latest APIs and your Minimum SDK Version to 16 to support devices running Android 4.1, but your app will crash if you use 5.0 APIs and run it on an Android 4.1 device (because Android 4.1 did not have any of 5.0’s APIs).
The Google Play Store decides which users to show your app to based on your minSdkVersion. If you’re having trouble deciding which version to set as your minimum, the current version distribution chart can help you decide.
The minSdkVersion is technically optional, but you should always set it! If you don’t know what to set it to, then set it to the same value as your compileSdkVersion.
It’s up to you to test your app on all the versions of Android between your Minimum SDK Version and the latest Android SDK version!
Target SDK Version
Compile SDK Version and Minimum SDK Version are arguably the most important SDK version settings that you need to understand. However, there’s a third SDK version called targetSdkVersion that’s often misunderstood and equally important to understand.
You should set the targetSdkVersion to the most recent version of Android that you have tested on. In this case, you are building and testing against Lollipop, so that’s what you’ll set your targetSdkVersion to.
Whenever a new version of Android comes out, you will want to update the targetSdkVersion to the latest Android version and test your app to fix any problems. If you don’t update the targetSdkVersion, Android devices will assume that your app wasn’t tested on the latest version of Android, so they may introduce some backward-compatibility behavior for your app to make sure your app still looks and feels the way you designed it for that older version of Android. It gets a little tricky, so the best policy is to always keep your targetSdkVersion up to date with the latest versions of Android.