In this android blog article, Let’s Understand the major different between compileSdkVersion & targetSdkVersion in Android Development, This both
CompileSdkVersion and TargetSdkVersion are very important settings that is configured into Android project while creating new project under
build.gradle file. They simply tells developer that which Android SDK version is been used to compile the code & which while be highest device it the app will support. Here’s the difference between the two:
𝐜𝐨𝐦𝐩𝐢𝐥𝐞𝐒𝐝𝐤𝐕𝐞𝐫𝐬𝐢𝐨𝐧 specifies which version of Android SDK will be used by android gradle to compile you android project. This means that your andriod application has the ability to use all that APIs is is been included into the specified version and less then specified version.
𝐅𝐨𝐫 𝐄𝐱𝐚𝐦𝐩𝐥𝐞, If your android project is set to 𝐜𝐨𝐦𝐩𝐢𝐥𝐞𝐒𝐝𝐤𝐕𝐞𝐫𝐬𝐢𝐨𝐧 to
30, it means that your android application has access to use all the APIs up to version 30. For example, let’s assume you want Camera2 API to be used, But the Camera2 API was introduced with Android 5.0 (i.e. API Level 21) and above, and you have already set 𝐜𝐨𝐦𝐩𝐢𝐥𝐞𝐒𝐝𝐤𝐕𝐞𝐫𝐬𝐢𝐨𝐧 to 30, That means you can use
Camera2 API without any issue. However, suppose you set compileSdkVersion lower then API Level 21 and you are trying to make use of Camera2 API, then you will get compile-time error because Camera2 API is not available below 𝐜𝐨𝐦𝐩𝐢𝐥𝐞𝐒𝐝𝐤𝐕𝐞𝐫𝐬𝐢𝐨𝐧 21.
𝐭𝐚𝐫𝐠𝐞𝐭𝐒𝐝𝐤𝐕𝐞𝐫𝐬𝐢𝐨𝐧 This version defines tell the android OS on which android SDK version the Application was designed and tested on and also indicates the API version the app is of compatibility and can run smoothly.
𝐅𝐨𝐫 𝐄𝐱𝐚𝐦𝐩𝐥𝐞, suppose your android project 𝐭𝐚𝐫𝐠𝐞𝐭𝐒𝐝𝐤𝐕𝐞𝐫𝐬𝐢𝐨𝐧 is set to
30, It Means that you has designed the app to run on device that support android 30 and above, and you made it sure that your android application will work smoothly abd behaves correctly as accepted on those devices.
📝 The summary, the
compileSdkVersion, determines a set of APIs that is been used for the build process, while the
targetSdkVersion specifies the intended API level for the app and indicates its compatibility with newer Android versions.
🎯 Ideally, the compileSdkVersion and targetSdkVersion should match, both pointing to the latest SDK. However, it’s crucial to thoroughly test the app’s compatibility with the changes introduced in that version.
💡 Therefore, understanding the distinction between compileSdkVersion and targetSdkVersion is vital for effective utilization in Android development projects. This ensures optimization, thorough testing, and smooth functioning of your app across various devices. Happy coding! 💻📱🚀