Resolve "Requires compile against Android API 33+" Error
Problem Statement
When compiling an Android application, you encounter the following Gradle sync error:
3 issues were found when checking AAR metadata:
1. Dependency 'androidx.core:core-ktx:1.9.0' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs.
2. Dependency 'androidx.core:core:1.9.0' requires compile against version 33 or later.
3. Dependency 'androidx.annotation:annotation-experimental:1.3.0' requires compile against version 33 or later.
:app is currently compiled against android-32.
This error occurs because your Android project uses libraries that require minimum API level 33 (compileSdkVersion 33
), but your project is currently configured to use a lower SDK version (32). The problem is specifically caused by these dependencies:
- androidx.core:core-ktx
- androidx.core:core
- androidx.annotation:annotation-experimental
Recommended Solution
Update compileSdkVersion
Update your app's compileSdkVersion
to 33 or higher. This solution keeps your dependencies current while resolving the compatibility issue.
Modify your module-level build.gradle
file (Groovy):
android {
compileSdk 33 // Update from 32→33
defaultConfig {
applicationId "com.example.app"
minSdk 21 // Keep your minSdk unchanged
targetSdk 33 // Optional but recommended
versionCode 1
versionName "1.0"
}
}
Kotlin DSL (build.gradle.kts
) equivalent:
android {
compileSdk = 33
defaultConfig {
minSdk = 21
targetSdk = 33 // Optional
}
}
Key benefits:
- Maintains secure and updated libraries
- Retains new Android features and improvements
- Preserves compatibility with newer devices
- Requires minimal code changes
Update Guidance
Update your targetSdkVersion
along with compileSdkVersion
to:
- Avoid compatibility issues
- Future-proof your app
- Align with Play Store requirements
Not Recommended
Avoid downgrading libraries to bypass the error (e.g., reverting to core-ktx:1.8.0
). This introduces potential:
- Security vulnerabilities
- Missing bug fixes
- Compatibility issues with newer devices
Additional Considerations
Android Gradle Plugin Compatibility
If updating to API 34+, verify your plugin version supports the SDK:
dependencies {
classpath 'com.android.tools.build:gradle:8.2.0' // Minimum for SDK 34
}
Library Conflicts
If issues persist after updating compileSdk
, inspect dependencies with:
./gradlew :app:dependencies --configuration releaseRuntimeClasspath
Look for version conflicts in transitive dependencies, particularly:
androidx.activity:activity
androidx.compose.runtime:runtime
Cordova Projects
Update your Cordova project’s config.xml
:
<preference name="android-targetSdkVersion" value="33" />
Version Comparison Table
Update requirements for common dependencies:
Library | Minimum API | Stable Version |
---|---|---|
androidx.core:core-ktx | 33 | 1.12.0+ |
androidx.appcompat:appcompat | 33 | 1.6.1+ |
com.google.android.material | 33 | 1.9.0+ |
androidx.annotation | 33 | 1.7.0+ |
Final Steps
- Update
compileSdkVersion
to 33+ - Sync Gradle
- Test app functionality
- Deploy to devices running different API levels
::: important After updating, run comprehensive tests on devices spanning your minSdkVersion
to targetSdkVersion
to ensure API changes don't affect behavior. :::
By updating your compileSdkVersion
, you maintain the latest library versions while ensuring compatibility with Android's newest platform features.