Junior — Middle
Why is it important to specify the targetSdk parameter in the build.gradle file for the project module?
sobes.tech AI
Answer from AI
The targetSdkVersion parameter in the build.gradle file indicates the version of Android for which the application is optimized and tested. This is important because Android supports backward compatibility, but system behavior may change depending on the target SDK version.
If targetSdkVersion is not specified or set to a lower version, the system may apply outdated or compatible modes, which can lead to incorrect application behavior on newer Android versions. Specifying the current version allows the use of new platform features and ensures that the application behaves as expected on modern devices.
Example in build.gradle:
android {
compileSdkVersion 33
defaultConfig {
applicationId "com.example.app"
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
}