minSdk vs targetSdk vs compileSdk

What is the difference between minSdk, targetSdk and compileSdk in your build Gradle script?

Vincent Tsen

--

Let’s have a look at what minSdk, targetSdk and compileSdk really means in build.gradle script.

android {
compileSdk 32
defaultConfig {
/*...*/
minSdk 21
targetSdk 32
/*...*/
}
}
  • minSdk — What is the minimum API Level required for the app to run?
  • targetSdk — Which API level the app was designed and tested on?
  • compileSdk — Which API level is used by Gradle to compile your app?

minSdk

If your minSdk is set to 21, your app cannot be run on any Android version that is below API level 21. If the Android version (API level 20) attempts to install your app, you get this error.

Installation did not succeed. The application could not be installed: INSTALL_FAILED_OLDER_SDK

The Google Play Store prevents the user from installing the app too if the phone’s Android version doesn’t meet the minSdk requirement by the app.

targetSdk

App runs on API level > targetSdk

If the app is run on the Android version (API level) that is higher than the targetSdk, the Android operating system will try to run backward compatibility behavior to match behavior as in targetSdk API level.

For example, runtime app permission is introduced in API level 23. Before API level 23, runtime app permission is not needed.

If your targetSdk is set to 22 and your app runs on Android version (API level 23), the Android OS will try to match the behavior as in API level 22. Thus, no runtime permission is requested.

If your targetSdk is set to 23 and your app runs on Android version (API level 23 or higher), runtime permission is requested.

App runs on API level < targetSdk

What about the app that runs on the Android version (API level) that is < targetSdk? The app behaves based on…

--

--