Question

Fix Incompatible Kotlin Metadata Version Error in Android/Gradle

kotlinandroidandroid-studio

Question

I get the following error when trying to build my Android app:

C:/Users/Lenovo/.gradle/caches/transforms-2/files-2.1/32f0bb3e96b47cf79ece6482359b6ad2/jetified-kotlin-stdlib-jdk7-1.5.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.16

Does this mean I need to update a module or dependency? If so, how do I update it correctly so the project builds again?

Short Answer

By the end of this page, you will understand what the Kotlin metadata version error means, why it happens in Android and Gradle projects, and how to fix it by aligning your Kotlin plugin, Gradle dependencies, and cached libraries to compatible versions.

Concept

Kotlin libraries are compiled with a specific Kotlin compiler version. During your build, the Kotlin compiler in your project reads metadata from those libraries.

In this error, your project expects an older Kotlin metadata format (1.1.16), but one of your dependencies, kotlin-stdlib-jdk7-1.5.0.jar, was compiled with a newer Kotlin version (1.5.1). That means your project is using an old Kotlin plugin or old build configuration, while one or more dependencies were built with a newer Kotlin release.

What the error really means

This part is the key:

Module was compiled with an incompatible version of Kotlin.
The binary version of its metadata is 1.5.1, expected version is 1.1.16

It means:

  • A library in your project was compiled with Kotlin 1.5.x
  • Your project is still compiling with a much older Kotlin compiler
  • The old compiler cannot understand the newer metadata format

Why this matters

In real projects, your build tools must agree on versions:

  • Kotlin Gradle plugin
  • Kotlin standard library
  • Android Gradle Plugin
  • Gradle wrapper
  • Sometimes third-party libraries that depend on Kotlin

If one part is too old and another is too new, the build can fail before your app even runs.

The usual fix

Most of the time, the correct fix is to upgrade the project's Kotlin version so it matches the Kotlin libraries being used. In some cases, you instead need to downgrade a dependency if the project must stay on an older setup.

For Android projects, upgrading Kotlin in the Gradle build files is the most common solution.

Mental Model

Think of Kotlin metadata like a document format.

  • Your dependency was saved as a newer file format
  • Your project is trying to open it with an older reader
  • The old reader does not understand the newer format

So the solution is usually one of these:

  • Upgrade the reader: update your Kotlin plugin/compiler
  • Use an older file: downgrade the dependency to a version compiled with your current Kotlin version

In practice, upgrading the Kotlin version is usually easier and more future-proof.

Take Quiz

Syntax and Examples

In Android and Gradle projects, Kotlin versions are commonly declared in one of these places.

Example: older build.gradle style

buildscript {
    ext.kotlin_version = '1.5.31'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

If your project currently has something much older, such as Kotlin 1.1.x, and a dependency uses Kotlin 1.5.x, you can get the metadata error.

Example: module dependency

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.31"
}

Usually, you should avoid mixing a very old Kotlin plugin with a newer stdlib version.

Example fix strategy

Use consistent versions:

buildscript {
    ext.kotlin_version = '1.5.31'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

And in the app module:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

Newer plugins DSL style

Some projects use this instead:

plugins {
    id 'com.android.application' version '8.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
}

The same principle applies: keep the Kotlin plugin compatible with your dependencies and Android Gradle Plugin.

Important note

The exact version you should use depends on your Android Gradle Plugin and Gradle wrapper versions. The core idea is not "update one random module" but align the whole Kotlin toolchain.

Step by Step Execution

Consider this simplified situation:

buildscript {
    ext.kotlin_version = '1.1.16'
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.0"
}

Here is what happens during the build:

  1. Gradle starts the Android build.
  2. The project loads the Kotlin Gradle plugin version 1.1.16.
  3. Your app depends on kotlin-stdlib-jdk7:1.5.0.
  4. That library was compiled with newer Kotlin metadata.
  5. The old Kotlin compiler tries to read that metadata.
  6. It fails because it only understands an older metadata format.
  7. Gradle stops with the incompatible version error.

After fixing the version mismatch

If you update the Kotlin plugin to a compatible version:

buildscript {
    ext.kotlin_version = '1.5.31'
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31"
}

Then the build flow becomes:

  1. Gradle loads a newer Kotlin plugin.
  2. The compiler understands the library metadata.
  3. Dependency resolution succeeds.
  4. Kotlin compilation continues normally.
  5. The app can build successfully.

Practical steps to try

  1. Check your Kotlin plugin version in project-level Gradle files.
  2. Check whether any dependency pulls in a much newer Kotlin stdlib.
  3. Update Kotlin plugin and stdlib to a compatible version.
  4. Sync Gradle.
  5. Clean and rebuild.
  6. If the error remains, clear Gradle cache and try again.

Real World Use Cases

This version mismatch appears often in real Android development.

1. Updating one library without updating Kotlin

You upgrade a dependency, and that dependency was built with a newer Kotlin version. Your project is still on an old Kotlin plugin, so the build breaks.

2. Opening an old Android project in a newer environment

A project created years ago may still use very old Kotlin and Gradle settings. Adding modern libraries can trigger metadata errors.

3. Copying Gradle snippets from different tutorials

One tutorial may use old buildscript syntax and old versions, while another uses modern Kotlin versions. Mixing them can create mismatches.

4. Team projects with inconsistent local environments

One developer upgrades a dependency or plugin, but the project files are not fully aligned. Another developer then gets build failures.

5. Cached dependency issues

Sometimes Gradle keeps old or conflicting cached artifacts, especially after several upgrades. Cleaning caches can help after version alignment.

Take Quiz

Real Codebase Usage

In real codebases, developers usually solve this with version alignment and centralized configuration.

Common patterns

Centralize versions

Store key versions in one place so plugin and dependencies stay in sync.

ext {
    kotlin_version = '1.5.31'
}

Upgrade toolchain together

Developers often update these together:

  • Kotlin plugin
  • Android Gradle Plugin
  • Gradle wrapper
  • Kotlin stdlib if explicitly declared

Use guard checks when upgrading

After changing build versions:

  • Sync Gradle
  • Run a clean build
  • Check dependency tree
  • Test on CI

Avoid forcing mismatched Kotlin libraries

If a library already brings the Kotlin stdlib transitively, manually forcing a different incompatible version can cause problems.

Clear stale caches when needed

Typical cleanup steps:

File > Invalidate Caches / Restart   (Android Studio)
./gradlew clean

On Windows:

gradlew clean

If needed, delete the .gradle cache directory and rebuild.

Good maintenance habit

Treat Kotlin version changes like infrastructure updates, not isolated library changes. In real projects, compatibility matters more than simply choosing the newest version.

Common Mistakes

1. Updating only one Kotlin dependency

Beginners often update kotlin-stdlib but leave the Kotlin Gradle plugin very old.

Broken example

buildscript {
    ext.kotlin_version = '1.1.16'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.0"
}

Why it fails

The compiler is old, but the library metadata is new.

Fix

Update both to compatible versions.

2. Thinking the problem is in your app module code

This error usually comes from build configuration, not your Kotlin source code.

Avoid this mistake

Check Gradle files before debugging app logic.

3. Ignoring transitive dependencies

You may not directly add kotlin-stdlib-jdk7:1.5.0, but another library may bring it in.

How to avoid it

Inspect dependencies using Gradle tools or the dependency tree.

4. Upgrading Kotlin without checking Gradle compatibility

A newer Kotlin plugin may require a compatible Android Gradle Plugin or Gradle wrapper.

Avoid this mistake

Upgrade related build tools together when necessary.

5. Forgetting to clean and sync

Even after fixing versions, Android Studio or Gradle caches may still reference old artifacts.

Fix

  • Sync project
  • Run clean build
  • Restart IDE if needed
  • Clear caches if the issue persists

6. Mixing very old and modern Gradle configuration examples

Some online examples use deprecated settings.

Avoid this mistake

Use one consistent build style and compatible versions across the whole project.

Comparisons

ApproachWhat it meansWhen to useProsCons
Upgrade Kotlin pluginUpdate the project's Kotlin compiler/plugin versionBest when your dependencies are modernUsually the correct long-term fixMay require Gradle or AGP updates too
Downgrade the dependencyUse an older library compiled with older KotlinUseful when maintaining a legacy projectSmaller change in some old projectsKeeps project on outdated stack
Clear Gradle cache onlyRemove stale cached filesOnly after fixing versionsCan solve cache-related leftoversDoes not fix real version mismatch by itself
Force stdlib version manuallyOverride Kotlin stdlib version in dependenciesSometimes useful for alignmentCan help unify versionsRisky if done without understanding compatibility

Kotlin plugin vs Kotlin stdlib

ItemRole
Kotlin Gradle pluginCompiles Kotlin code during the build
Kotlin stdlibRuntime library used by Kotlin code

These should usually be on compatible versions.

Main idea

If the compiler is older than the library metadata, the build can fail. That is why upgrading the Kotlin plugin is often more important than changing just one dependency.

Take Quiz

Cheat Sheet

Quick diagnosis

If you see this:

Module was compiled with an incompatible version of Kotlin

check for a mismatch between:

  • Kotlin Gradle plugin version
  • Kotlin stdlib version
  • Third-party libraries compiled with newer Kotlin

Common fix

Update Kotlin in your Gradle config so versions are compatible.

Older style

buildscript {
    ext.kotlin_version = '1.5.31'
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

Dependency

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

Cleanup steps

gradlew clean

Then sync and rebuild.

If needed:

  • Invalidate IDE caches
  • Delete .gradle caches
  • Re-download dependencies

Rules to remember

  • Keep Kotlin plugin and Kotlin libraries compatible
  • Do not mix very old compiler versions with new Kotlin libraries
  • Check transitive dependencies too
  • Toolchain compatibility matters in Android projects

Fast troubleshooting checklist

  • What Kotlin plugin version is my project using?
  • What Kotlin stdlib version is being pulled in?
  • Did I recently upgrade a dependency?
  • Is my Android Gradle Plugin too old?
  • Did I clean and rebuild after changes?

FAQ

Why does the Kotlin metadata version error happen?

It happens when your project's Kotlin compiler is older than a library compiled with a newer Kotlin version.

Do I need to update the module mentioned in the error?

Usually not that specific file directly. You typically update your project's Kotlin plugin and align dependency versions in Gradle.

How do I find my Kotlin version in an Android project?

Look in project-level build.gradle, settings.gradle, version catalog files, or the plugins block for org.jetbrains.kotlin.android or kotlin-gradle-plugin.

Can I fix this by deleting the .gradle folder?

Only if the real issue is stale cache. If versions are incompatible, cache deletion alone will not solve it.

Should I upgrade Kotlin or downgrade the dependency?

Upgrade Kotlin if possible. Downgrade the dependency only when you must keep a legacy build setup.

Is this caused by my Kotlin source code?

Usually no. It is most often a build configuration and dependency compatibility issue.

What if updating Kotlin causes other build errors?

Then you may also need to update the Android Gradle Plugin and Gradle wrapper to compatible versions.

Do third-party libraries cause this error?

Yes. A library can transitively bring in a newer Kotlin stdlib or be compiled with a newer Kotlin version than your project supports.

Take Quiz

Mini Project

Description

Create a small Android/Gradle configuration exercise that simulates a Kotlin version mismatch and then fixes it by aligning versions. This helps you practice reading build files and understanding where Kotlin versions are defined.

Goal

Update an Android project's build configuration so the Kotlin plugin and Kotlin libraries use compatible versions and the project can build successfully.

Requirements

Requirement 1 Requirement 2 Requirement 3

Take Quiz

Keep learning

Related questions

View more