Skip to content

Resolve "Requires compile against Android API 33+" Error

Problem Statement

When compiling an Android application, you encounter the following Gradle sync error:

sh
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

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):

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:

kotlin
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:

  1. Avoid compatibility issues
  2. Future-proof your app
  3. 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:

gradle
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:

shell
./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:

xml
<preference name="android-targetSdkVersion" value="33" />

Version Comparison Table

Update requirements for common dependencies:

LibraryMinimum APIStable Version
androidx.core:core-ktx331.12.0+
androidx.appcompat:appcompat331.6.1+
com.google.android.material331.9.0+
androidx.annotation331.7.0+

Final Steps

  1. Update compileSdkVersion to 33+
  2. Sync Gradle
  3. Test app functionality
  4. 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.