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:
Android compileSdkVersion
ππ¨π¦π©π’π₯ππππ€πππ«π¬π’π¨π§ 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.
Android targetSdkVersion
πππ«π πππππ€πππ«π¬π’π¨π§ 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.
Conclusion
π 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! π»π±π