The Curse of minCompileSdk (31): How to Defeat the AAR Error in Kotlin

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction: Your project won't build? You are not alone

\n\n

Imagine: you're writing in Kotlin, everything is going great, but suddenly — bam! — the build fails with a mysterious message: The minCompileSdk (31) specified in a dependency's AAR metadata. Sound familiar? This error is one of the most popular "pitfalls" on Stack Overflow (thousands of views and hundreds of comments). It occurs when you use a library that requires a newer version of compileSdk than the one configured in your project.

\n\n

In this article, we will break down how to fix the minCompileSdk (31) error in AAR metadata for Kotlin and Java projects. You will learn the causes, get ready-made solutions, and understand how to avoid this problem in the future. Let's go!

\n\n

What is minCompileSdk and why does it break the build?

\n\n

Let's start with the theory. Every Android project has its own compileSdk — the version of the Android SDK it compiles with. Libraries (AAR) can also specify a minimum compileSdk they require. If your version is lower — Gradle throws an error. This is a safeguard against incompatibility: the library might use APIs that don't exist in older SDKs.

\n\n

The error The minCompileSdk (31) specified in a dependency's AAR metadata literally says: "Hey, this library requires compilation with SDK 31 (Android 12) or higher, but you have a lower one!".

\n\n

Typical scenarios of occurrence

\n
    \n
  • You added a new library (e.g., androidx.compose or Firebase) that has updated its requirements to SDK 31+.
  • \n
  • You are using an old project template with compileSdk = 30.
  • \n
  • You forgot to update Gradle and SDK Tools.
  • \n
\n\n

How to fix the minCompileSdk (31) error in AAR: 3 proven methods

\n\n

Here are step-by-step solutions for Kotlin and Java. Note: the code is in Kotlin (DSL), but the logic is the same for Groovy.

\n\n

Method 1: Increase compileSdk (recommended)

\n

The most correct path is to update compileSdk to the version required by the library. Usually this is 31 (Android 12) or 33 (Android 13).

\n\n

Steps:

\n
    \n
  1. Open the file build.gradle.kts (module level app).
  2. \n
  3. Find the android section.
  4. \n
  5. Change compileSdk to the required value.
  6. \n
\n\n
android {\n    compileSdk = 33 // Or 31, 32 — depending on requirements\n\n    defaultConfig {\n        minSdk = 21\n        targetSdk = 33\n        // ...\n    }\n}\n
\n\n

Why does this work? You are simply meeting the dependency's requirements. If the library asks for SDK 31, give it SDK 31. Don't forget to also install the corresponding SDK in Android Studio (SDK Manager → Android 12.0 (API 31)).

\n\n

Method 2: Downgrade the library version

\n

If you don't want to increase compileSdk (e.g., due to compatibility with older devices), you can roll back the library to a version that doesn't require SDK 31.

\n\n

Example: Instead of implementation("androidx.compose:compose-bom:2023.10.01"), use an older version, e.g., 2022.10.00.

\n\n
dependencies {\n    // Was (causes error)\n    // implementation("androidx.compose:compose-bom:2023.10.01")\n\n    // Now (stable version without SDK 31+ requirement)\n    implementation("androidx.compose:compose-bom:2022.10.00")\n}\n
\n\n

This is a temporary solution, but it helps if you are stuck on an old SDK. The main downside is that you lose new features and security fixes.

\n\n

Method 3: Override minCompileSdk via Gradle (exotic)

\n

There is a tricky, but undocumented method — to override AAR metadata through Gradle configuration. This method is not recommended for production, but can save you if the library is not updated.

\n\n
andr                

Blogs

Book Recommendations