Demystifying compileSdk, targetSdk and minSdk on Android

Do you know the difference between compileSdk, targetSdk and minSdk on Android? Let’s understand it.

compileSdkVersion

  1. An integer designating the API Level that the application compiled against.
  2. This means you can use Android API features included upto that version of the API.
  3. If you set compileSdkVersion to 30 and try to use API 31 features, you will get a compilation error.
  4. If you set compileSdkVersion to 31, you can still run the app on a API 30 device as long as your app’s execution paths do not attempt to invoke any APIs specific to API 31.

targetSdkVersion

  1. An integer designating the API Level that the application targets.
  2. This informs the system that you have tested against the target version.
  3. If you set targetSdkVersion to 30 and try to run on device having API 31, the system may enable compatibility behaviors to ensure that your app continues to work the way you expect.
  4. If not set, the default value is set to minSdkVersion.

minSdkVersion

  1. An integer designating the minimum API Level required for the application to run.
  2. If you set minSdkVersion to 30 and user try to install it on API 29, Android system will prevent the installation.
  3. If you do not declare this attribute, the system assumes a default value of “1”, which indicates that your application is compatible with all versions of Android.

To summarize, use the following style for choosing sdk

minSdkVersion (choose lowest possible SDK) <= targetSdkVersion == compileSdkVersion (choose latest SDK)

Share with your friends

Leave a Reply

Your email address will not be published. Required fields are marked *