Difference between compileSdkVersion and targetSdkVersion


Introduction

An SDK (Software Development Kit) provides a set of tools such as libraries, tools and API to the developer for building the application for a specific platform. The SDK Version refers to the version of android platform that an app is built against. Each Version of the Android SDK corresponds to a specific version of the Android operating System. For Example Android 11 has an SDK version of 30, while Android 10 has an SDK version of 29 and so on.

When developing an Android app, it's essential to understand the difference between compileSdkVersion and targetSdkVersion. These two terms can sometimes be confusing for developers, and understanding their meaning is crucial to ensuring your app runs smoothly on different devices and operating systems.

You can find these compileSdkVersion and targetSdkVersion in build.gradle file as given below:

build.gradle (app)

android {
   compileSdk 33
   defaultConfig {
       minSdk 21
       targetSdk 33
       versionCode 1
       versionName "1.0"
   }
}

What is compileSdkVersion in Android?

The compileSdkVersion is the version of the Android SDK that you use to compile your app. This version determines which APIs and features you can use in your app. When you compile your app with a particular compileSdkVersion, you're telling the build system to use that specific version's API and ensure that your code is compatible with that version. However, it's worth noting that using a higher compileSdkVersion doesn't necessarily mean your app will have access to new features or APIs that weren't present in the lower version.

What is targetSdkVersion in Android?

The targetSdkVersion is the version of the Android API that your app is designed to run on. This version tells the operating system which APIs and features your app expects to use. When you set the targetSdkVersion to a specific version, you're telling the system that your app is optimized for that version, and the system should enable any compatibility behaviors necessary to ensure your app runs correctly on that version.

Setting the targetSdkVersion is particularly important when it comes to Android's versioning system. Android releases updates regularly, and each version may include changes to the behavior of the OS or its APIs. When you set the targetSdkVersion to the latest available version, you're telling the OS that your app is optimized for that version and has been tested to work correctly with any changes that may have been introduced.

It's important to note that setting the targetSdkVersion doesn't mean your app can't run on older versions of the OS. Instead, it informs the system that your app is designed to work with that version, and the system will enable any compatibility behaviors necessary to ensure your app runs smoothly. However, if you set the targetSdkVersion to an older version of the API, your app may miss out on any new features and optimizations introduced in the newer versions.

Difference between targetSdkVersion and compileSdkVersion

Compile SDK Version

Target SDK Version

Compile SDK Version is a minimum version of android sdk that can be used to compile our application.

Target SDK version is a version of an android application that your app was designed to turn on and can be changed while developing your app.

Compile SDK version can be changed while developing your application.

Target SDK version cannot be changed.

It is used to test compatibility of your application.

It is used to make sure that your app behaves as expected on an Android device.

It can be used to change the new API features.

It cannot be used to change new API features.

Compile SDK Version can be an older API level than the target API level

Target SDK Version should always be the same or higher than the compile SDK version.

Conclusion

In summary, the compileSdkVersion is the version of the Android SDK used to compile your app, while the targetSdkVersion is the version of the Android API your app is optimized for. Setting the compileSdkVersion and targetSdkVersion correctly is crucial to ensuring your app runs smoothly on different devices and operating systems.

Updated on: 09-May-2023

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements