Question
How to Fix minCompileSdk AAR Metadata Errors in Android Java or Kotlin
Question
I am building an Android app in Java or Kotlin and get this build error:
The minCompileSdk (31) specified in a dependency's AAR metadata
(META-INF/com/android/build/gradle/aar-metadata.properties) is greater
than this module's compileSdkVersion (android-30).
Dependency: androidx.core:core-ktx:1.7.0-alpha02
The dependency requires a higher compileSdkVersion than the one currently used by my app. How can I resolve this error correctly in a native Android Java or Kotlin project?
Short Answer
By the end of this page, you will understand what compileSdkVersion means, why Android dependencies can require a minimum compile SDK, and how to fix the minCompileSdk AAR metadata error safely. You will also learn how to choose between upgrading your SDK version and downgrading a dependency when needed.
Concept
Android libraries are published with metadata that tells Gradle what environment they need in order to compile correctly. One part of that metadata is minCompileSdk, which means the minimum Android SDK level your project must compile against to use that library.
In the error shown, your app is compiling with Android 30:
compileSdkVersion 30
But the dependency requires at least Android 31:
minCompileSdk 31
That creates a mismatch, so Gradle stops the build.
What compileSdkVersion really means
compileSdkVersion is the Android API level used at build time. It controls:
- which Android APIs your code can reference
- which library versions are compatible with your build
- whether newer AndroidX packages can be compiled
It is not the same as:
minSdkVersion: the minimum Android version your app can run ontargetSdkVersion: the Android version your app is optimized for
Why this matters
Modern AndroidX libraries often depend on newer SDK APIs, build tools, or metadata rules. If your project compiles against an older SDK than the library requires, Gradle cannot guarantee a correct build. That is why this check exists.
The usual fix
Mental Model
Think of compileSdkVersion as the edition of a textbook your project uses while studying.
- Your app is using the Android 30 textbook.
- The library was written for the Android 31 textbook.
- If the library references material that only exists in edition 31, the edition 30 book will be missing pages.
So Gradle says: you cannot study this library with an older textbook.
Important detail:
compileSdkVersionaffects building the appminSdkVersionaffects which devices can run the app
You can often raise compileSdkVersion without increasing minSdkVersion.
Syntax and Examples
In Android projects, this setting is usually inside your app module's build.gradle or build.gradle.kts file.
Groovy DSL (build.gradle)
android {
compileSdkVersion 31
defaultConfig {
minSdkVersion 21
targetSdkVersion 31
}
}
Kotlin DSL (build.gradle.kts)
android {
compileSdk = 31
defaultConfig {
minSdk = 21
targetSdk = 31
}
}
Example dependency causing the issue
dependencies {
implementation "androidx.core:core-ktx:1.7.0-alpha02"
}
If that library requires minCompileSdk 31, your project must use at least:
compileSdkVersion 31
If you cannot upgrade compile SDK yet
Use an older compatible dependency version instead:
dependencies {
implementation "androidx.core:core-ktx:1.6.0"
}
The exact older version depends on your project and plugin setup.
Step by Step Execution
Consider this project:
android {
compileSdkVersion 30
}
dependencies {
implementation "androidx.core:core-ktx:1.7.0-alpha02"
}
Gradle starts the build and checks dependency metadata.
Step 1: Read the app configuration
Gradle sees:
compileSdkVersion = 30
Step 2: Read the library metadata
For androidx.core:core-ktx:1.7.0-alpha02, Gradle reads AAR metadata and finds:
minCompileSdk = 31
Step 3: Compare the two values
Gradle compares:
- project compile SDK:
30 - dependency minimum compile SDK:
31
Since 30 < 31, the dependency is not allowed.
Step 4: Build fails
Gradle stops with the error because the library expects newer Android APIs than your build configuration provides.
Step 5: Fix the mismatch
You can fix it in one of two ways:
Option A: Upgrade the project
android {
compileSdkVersion 31
}
Real World Use Cases
This issue appears often in real Android projects when:
- upgrading AndroidX dependencies like
core-ktx,work-runtime,activity, orfragment - copying dependency versions from tutorials that use newer SDKs
- mixing old project settings with newer libraries
- updating one library indirectly through a dependency tree
- opening an older codebase in a newer Android Studio setup
Practical examples
- A team upgrades
androidx.work:work-runtimefor bug fixes, but the app still compiles with SDK 30. - A developer adds a new Material or AndroidX library version that now requires SDK 31.
- A company maintains an older app but wants security fixes from new dependencies.
In each case, the solution is to align the project's compile SDK with the library requirements or choose compatible versions.
Real Codebase Usage
In real projects, developers usually handle this with a few common patterns.
1. Keep compile SDK reasonably current
Many teams update compileSdk regularly so AndroidX upgrades are easier.
android {
compileSdkVersion 34
}
This does not automatically increase minSdkVersion.
2. Centralize versions
Projects often store SDK and library versions in one place.
Example
ext {
compileSdk = 34
minSdk = 21
targetSdk = 34
}
Then reuse them in modules.
3. Avoid random alpha dependencies
The error example uses an alpha version:
androidx.core:core-ktx:1.7.0-alpha02
In production codebases, stable versions are usually safer unless you need a preview feature.
4. Validate dependency upgrades in pull requests
Teams often review:
- required SDK changes
- Android Gradle Plugin compatibility
- CI build results
- release notes for libraries
5. Prefer upgrading over forcing a workaround
Trying to bypass metadata checks is usually a bad idea. The proper fix is version alignment, not suppression.
Common Mistakes
1. Confusing compileSdkVersion with minSdkVersion
A very common mistake is thinking this error means the app no longer supports older devices.
Broken understanding:
android {
minSdkVersion 31
}
This is usually unnecessary.
Correct idea:
android {
compileSdkVersion 31
minSdkVersion 21
}
You can often keep the same minSdkVersion.
2. Updating only the dependency
Beginners often upgrade a library without checking SDK requirements.
implementation "androidx.core:core-ktx:1.7.0-alpha02"
If the library needs a newer compile SDK, the project config must be updated too.
3. Using alpha versions unnecessarily
Alpha versions may require newer SDKs or tools sooner.
Broken choice:
implementation "androidx.core:core-ktx:1.7.0-alpha02"
Safer choice when possible:
implementation "androidx.core:core-ktx:1.6.0"
4. Forgetting to install the SDK platform
Comparisons
| Concept | Purpose | Affects build? | Affects device support? |
|---|---|---|---|
compileSdkVersion | Android API level used to compile the app | Yes | No |
minSdkVersion | Lowest Android version the app can run on | Indirectly | Yes |
targetSdkVersion | Android version the app is optimized for | Yes, behavior-related | No directly |
Upgrade compile SDK vs downgrade dependency
| Option | When to use it | Pros | Cons |
|---|---|---|---|
Cheat Sheet
Quick fix
If a dependency says:
minCompileSdk = 31
then your module must use:
compileSdkVersion 31
or higher.
Common locations
Groovy
android {
compileSdkVersion 31
}
Kotlin DSL
android {
compileSdk = 31
}
Important rule
compileSdkVersionis a build-time setting.- It is not the same as
minSdkVersion. - Raising
compileSdkVersionusually does not force you to raiseminSdkVersion.
If upgrade is not possible
Use an older version of the dependency that supports your current compile SDK.
Typical workflow
- Read the error message
- Find the required
minCompileSdk - Update
compileSdkVersionto that value or higher
FAQ
What does minCompileSdk mean in Android?
It is the minimum SDK level your project must compile against to use that dependency.
Does this mean I must increase minSdkVersion too?
No. Usually you only need to increase compileSdkVersion. Your app can still support older devices if minSdkVersion stays the same.
Why does AndroidX require a newer compile SDK?
Newer AndroidX versions may depend on newer Android APIs, build metadata, or tooling expectations.
Can I ignore the AAR metadata error?
You should not. The proper fix is to align your project SDK and dependency versions.
Should I use an older dependency instead?
Yes, if you cannot upgrade your compile SDK yet. Choose a version compatible with your current setup.
Is targetSdkVersion the same as compileSdkVersion?
No. compileSdkVersion affects building the app. targetSdkVersion affects how your app is expected to behave on newer Android versions.
Why did this happen after adding an alpha dependency?
Alpha versions often adopt newer SDK requirements earlier than stable versions.
Mini Project
Description
Build a small Android module configuration that uses an AndroidX dependency correctly by matching the project's compile SDK to the library requirement. This demonstrates how to prevent dependency metadata build errors in a realistic app setup.
Goal
Configure an Android app so that a modern AndroidX dependency builds successfully without changing device support unnecessarily.
Requirements
- Create or edit an Android app module build file.
- Set a compatible
compileSdkVersionorcompileSdkvalue. - Keep
minSdkVersionlower than the compile SDK. - Add an AndroidX dependency such as
core-ktx. - Ensure the configuration is valid for a normal build.
Keep learning
Related questions
Accessing Kotlin Extension Functions from Java
Learn how Kotlin extension functions are compiled and how to call them correctly from Java with clear examples and common pitfalls.
Android AlarmManager Example: Scheduling Tasks with AlarmManager
Learn how to use Android AlarmManager to schedule tasks, set alarms, and handle broadcasts with a simple beginner example.
Android Foreground Service Notification Channels in Kotlin
Learn why startForeground fails on Android 8.1 and how to create a valid notification channel for foreground services in Kotlin.