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.
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
}
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:
- Gradle starts the Android build.
- The project loads the Kotlin Gradle plugin version
1.1.16. - Your app depends on
kotlin-stdlib-jdk7:1.5.0. - That library was compiled with newer Kotlin metadata.
- The old Kotlin compiler tries to read that metadata.
- It fails because it only understands an older metadata format.
- 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:
- Gradle loads a newer Kotlin plugin.
- The compiler understands the library metadata.
- Dependency resolution succeeds.
- Kotlin compilation continues normally.
- The app can build successfully.
Practical steps to try
- Check your Kotlin plugin version in project-level Gradle files.
- Check whether any dependency pulls in a much newer Kotlin stdlib.
- Update Kotlin plugin and stdlib to a compatible version.
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.
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
Comparisons
| Approach | What it means | When to use | Pros | Cons |
|---|---|---|---|---|
| Upgrade Kotlin plugin | Update the project's Kotlin compiler/plugin version | Best when your dependencies are modern | Usually the correct long-term fix | May require Gradle or AGP updates too |
| Downgrade the dependency | Use an older library compiled with older Kotlin | Useful when maintaining a legacy project | Smaller change in some old projects | Keeps project on outdated stack |
| Clear Gradle cache only | Remove stale cached files | Only after fixing versions | Can solve cache-related leftovers | Does not fix real version mismatch by itself |
| Force stdlib version manually | Override Kotlin stdlib version in dependencies | Sometimes useful for alignment | Can help unify versions | Risky if done without understanding compatibility |
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
.gradlecaches - 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
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.
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
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.