The Android SDK and API levels help your app work on different Android devices and versions.
Android SDK and API levels in Android Kotlin
android {
compileSdk = 33
defaultConfig {
minSdk = 21
targetSdk = 33
}
}compileSdk is the Android version your app is built against.
minSdk is the oldest Android version your app supports.
targetSdk is the Android version your app is tested for and optimized to run on.
android {
compileSdk = 33
defaultConfig {
minSdk = 21
targetSdk = 33
}
}android {
compileSdk = 30
defaultConfig {
minSdk = 16
targetSdk = 30
}
}android {
compileSdk = 33
defaultConfig {
minSdk = 33
targetSdk = 33
}
}This is a simple Android app setup in Kotlin that supports devices with Android 5.0 (API 21) and newer.
plugins {
id("com.android.application")
kotlin("android")
}
android {
compileSdk = 33
defaultConfig {
applicationId = "com.example.sdkapilevel"
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"
}
}
fun main() {
println("App supports Android API 21 and above.")
}Always test your app on devices or emulators with different API levels to catch compatibility issues.
Using a higher compileSdk lets you use new Android features but does not affect which devices can install your app.
Setting minSdk too high limits your app to fewer devices, but setting it too low may require extra work to support old versions.
The Android SDK and API levels control which Android versions your app supports and uses.
compileSdk is the version you build against, minSdk is the oldest supported version, and targetSdk is the version your app is optimized for.
Choosing the right API levels helps your app reach more users and use new features safely.
Practice
minSdk version specify in an Android app?Solution
Step 1: Understand
minSdkmeaningminSdkdefines the minimum Android version that can run the app.Step 2: Differentiate from other SDK versions
compileSdkis for building,targetSdkis optimization, butminSdkis the oldest supported version.Final Answer:
The oldest Android version your app can run on -> Option DQuick Check:
minSdk= oldest supported version [OK]
- Confusing minSdk with compileSdk
- Thinking minSdk is the target optimization version
- Assuming minSdk is the latest Android version
compileSdk version to 33 in a Kotlin DSL Gradle file?Solution
Step 1: Identify Kotlin DSL syntax for compileSdk
In Kotlin DSL,compileSdkis assigned directly with=.Step 2: Compare options
compileSdkVersion 33is Groovy syntax without assignment,compileSdkVersion = 33uses the wrong property name, andcompileSdk(33)is invalid function call syntax. OnlycompileSdk = 33is correct.Final Answer:
compileSdk = 33 -> Option CQuick Check:
Kotlin DSL usescompileSdk = 33[OK]
- Using Groovy syntax in Kotlin DSL
- Omitting equals sign
- Using method call syntax incorrectly
android {
compileSdk = 31
minSdk = 21
targetSdk = 30
}
What is the highest Android version your app is optimized for?Solution
Step 1: Identify meaning of targetSdk
targetSdkis the Android version the app is optimized for and tested against.Step 2: Check given values
Here,targetSdkis 30, so the app is optimized for Android 30.Final Answer:
30 -> Option AQuick Check:
targetSdk = 30 means optimized for Android 30 [OK]
- Confusing compileSdk with targetSdk
- Thinking minSdk is optimization version
- Choosing compileSdk as optimization version
minSdk = 30 but want your app to run on Android 21 devices. What is the problem in this Gradle config?
android {
compileSdk = 33
minSdk = 30
targetSdk = 33
}Solution
Step 1: Understand minSdk role
minSdksets the lowest Android version the app supports.Step 2: Check compatibility with Android 21
SinceminSdkis 30, devices with Android 21 cannot run the app.Final Answer:
minSdk is too high, app won't run on Android 21 -> Option BQuick Check:
minSdk = 30 excludes Android 21 devices [OK]
- Thinking compileSdk affects device compatibility
- Assuming targetSdk limits device support
- Believing app runs on all versions regardless of minSdk
Solution
Step 1: Understand minSdk and targetSdk roles
minSdkis the oldest supported version;targetSdkis the optimized version.Step 2: Use runtime checks for new features
To support API 21 devices but use API 31 features, keepminSdk = 21, settargetSdk = 31, and check API level at runtime before using new features.Step 3: Evaluate options
SetminSdk = 21,targetSdk = 31, and use runtime checks for API 31 features correctly sets minSdk and targetSdk and mentions runtime checks. Others either restrict support or use wrong compileSdk.Final Answer:
Set minSdk = 21, targetSdk = 31, and use runtime checks for API 31 features -> Option AQuick Check:
minSdk low + targetSdk high + runtime checks = safe feature use [OK]
- Raising minSdk and losing older device support
- Not using runtime checks for new APIs
- Setting compileSdk lower than targetSdk
Ready to prove it?
Pass the test and this pattern moves unknown
