Question

How to Fix minCompileSdk AAR Metadata Errors in Android Java or Kotlin

kotlinjavaandroidgradle

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 on
  • targetSdkVersion: 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

The most common solution is to update your project to compile with the required SDK level or higher. In this case, move from 30 to 31 or above.

If you cannot upgrade yet, the other option is to use an older dependency version that still supports your current compile SDK.

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:

  • compileSdkVersion affects building the app
  • minSdkVersion affects which devices can run the app

You can often raise compileSdkVersion without increasing minSdkVersion.

Take Quiz

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.

After changing the version

Usually you should:

  1. Sync Gradle
  2. Rebuild the project
  3. Install the required SDK platform from Android Studio if missing

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
}

Option B: Use an older library version

dependencies {
    implementation "androidx.core:core-ktx:1.6.0"
}

Step 6: Sync and rebuild

After changing the configuration, sync Gradle and build again. If SDK 31 is not installed, Android Studio will prompt you to install it.

Real World Use Cases

This issue appears often in real Android projects when:

  • upgrading AndroidX dependencies like core-ktx, work-runtime, activity, or fragment
  • 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-runtime for 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.

Take Quiz

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

Even after updating compileSdkVersion, the build can still fail if the Android SDK platform is not installed locally.

5. Editing the wrong module

In multi-module projects, make sure you update the module that actually has the failing dependency.

6. Trying to suppress the error instead of fixing it

This metadata check exists for a reason. Ignoring it can lead to broken builds or runtime issues.

Comparisons

ConceptPurposeAffects build?Affects device support?
compileSdkVersionAndroid API level used to compile the appYesNo
minSdkVersionLowest Android version the app can run onIndirectlyYes
targetSdkVersionAndroid version the app is optimized forYes, behavior-relatedNo directly

Upgrade compile SDK vs downgrade dependency

OptionWhen to use itProsCons
Upgrade compileSdkVersionPreferred in most casesKeeps newer libraries, better compatibility with modern AndroidXMay require SDK/tooling updates
Downgrade dependencyUseful when project constraints block upgradesQuick fix for older codebasesMisses newer features and fixes

Stable vs alpha dependency versions

Version typeBest forRisk level
StableProduction appsLower
Alpha/BetaTesting or preview featuresHigher
Take Quiz

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

  • compileSdkVersion is a build-time setting.
  • It is not the same as minSdkVersion.
  • Raising compileSdkVersion usually does not force you to raise minSdkVersion.

If upgrade is not possible

Use an older version of the dependency that supports your current compile SDK.

Typical workflow

  1. Read the error message
  2. Find the required minCompileSdk
  3. Update compileSdkVersion to that value or higher
  4. Install the SDK platform in Android Studio
  5. Sync and rebuild

Watch out for

  • alpha or beta dependencies
  • wrong module configuration
  • outdated Android Gradle Plugin
  • missing local SDK installation

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.

Take Quiz

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 compileSdkVersion or compileSdk value.
  • Keep minSdkVersion lower than the compile SDK.
  • Add an AndroidX dependency such as core-ktx.
  • Ensure the configuration is valid for a normal build.
Take Quiz

Keep learning

Related questions

View more