Question
Fix Hilt Unsupported Metadata Version Error in Kotlin
Question
I am trying to run an Android project with Kotlin 1.5.10 using the following Gradle plugins:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
and these dependencies:
dependencies {
// Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0-beta01"
implementation "androidx.hilt:hilt-navigation-compose:1.0.0-alpha01"
implementation 'com.android.support:palette-v7:28.0.0'
}
After upgrading to:
kotlin_version = "1.5.10"
I get this build error:
error: [Hilt]
Unsupported metadata version. Check that your Kotlin version is >= 1.0:
java.lang.IllegalStateException: Unsupported metadata version. Check that your Kotlin version is >= 1.0
at dagger.internal.codegen.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:206)
at dagger.internal.codegen.kotlin.KotlinMetadata.from(KotlinMetadata.java:186)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133)
...
How can I fix this Hilt error when using Kotlin 1.5.10?
Short Answer
This page explains why the "Unsupported metadata version" error happens when using Hilt with Kotlin in Android projects. You will learn that the real cause is usually a version mismatch between Kotlin, Hilt, annotation processors, and AndroidX Hilt libraries. By the end, you will know how to align compatible versions, update old dependencies, and avoid this kind of build failure in future upgrades.
Concept
When you compile Kotlin code, the compiler stores metadata inside the generated class files. Tools like Hilt, Dagger, and other annotation processors read that metadata to understand Kotlin-specific features such as nullability, properties, and constructors.
If a library such as Hilt was built to understand an older Kotlin metadata format, and your project uses a newer Kotlin compiler, the processor may fail while reading that metadata. That is what causes errors like:
Unsupported metadata version
In this case, the issue is not that Kotlin is missing. The issue is usually that:
- your Kotlin version is newer than what your Hilt version supports
- your Hilt compiler is outdated
- your AndroidX Hilt artifacts are mixed across incompatible alpha/beta versions
- your project contains old support libraries or other outdated dependencies
Why this matters in real programming:
- Dependency injection tools rely heavily on annotation processing
- Build tools are sensitive to version compatibility
- Upgrading only one tool, such as Kotlin, can break the build if the rest of the stack is not upgraded too
So the core concept here is dependency version compatibility in Android builds, especially for Kotlin + kapt + Hilt.
Mental Model
Think of Kotlin metadata like a document written in a specific file format.
- Kotlin compiler writes the document
- Hilt compiler reads the document
If the writer starts producing a newer format, but the reader only understands the old one, the reader fails.
That is exactly what is happening here:
- Kotlin 1.5.10 writes newer metadata
- Hilt 2.33-beta is too old to read it correctly
- Build fails during annotation processing
So the fix is usually not to change your app code. The fix is to make sure the writer and reader speak the same version language.
Syntax and Examples
The main fix is to upgrade Hilt and related tooling so it matches your Kotlin version.
A cleaner modern dependency setup looks like this:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
android {
// android config
}
dependencies {
implementation "com.google.dagger:hilt-android:2.40.5"
kapt "com.google.dagger:hilt-android-compiler:2.40.5"
}
If you are using ViewModel integration, prefer modern artifacts that match your AndroidX versions rather than mixing old alpha/beta dependencies.
Example of the problem
ext.kotlin_version = "1.5.10"
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
This setup is risky because Hilt 2.33-beta predates Kotlin 1.5.10 support.
Example of the fix
ext.kotlin_version = "1.5.10"
implementation "com.google.dagger:hilt-android:2.37"
kapt "com.google.dagger:hilt-android-compiler:2.37"
Depending on the rest of your project, you may need an even newer Hilt version. The key idea is:
- do not keep an old Hilt version while upgrading Kotlin
Also avoid mixing old support libraries
This dependency is from the old support library system:
implementation 'com.android.support:palette-v7:28.0.0'
In AndroidX projects, use the AndroidX equivalent instead:
Step by Step Execution
Consider this simplified build setup:
ext.kotlin_version = "1.5.10"
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
Here is what happens step by step:
-
Gradle starts the build
- It applies the Kotlin plugin, Android plugin, kapt, and Hilt plugin.
-
Kotlin compiles your source files
- Kotlin 1.5.10 generates class files with Kotlin metadata.
-
kapt runs annotation processors
- Hilt's compiler inspects your classes and annotations.
-
Hilt reads Kotlin metadata
- It tries to parse the metadata written by Kotlin 1.5.10.
-
Old Hilt compiler cannot understand the new format
- It throws:
Unsupported metadata version
- The build fails before app compilation finishes
After upgrading Hilt
ext.kotlin_version = "1.5.10"
implementation "com.google.dagger:hilt-android:2.37"
kapt "com.google.dagger:hilt-android-compiler:2.37"
Now the flow changes:
- Kotlin 1.5.10 compiles code.
Real World Use Cases
Version compatibility issues like this appear often in real Android work.
1. Upgrading Kotlin in an existing app
A team updates Kotlin for language improvements, but the build starts failing because annotation processors such as Hilt, Room, or Moshi codegen are still on older versions.
2. Migrating a project to AndroidX
An app still contains old support libraries while newer tools are added. This can lead to confusing dependency conflicts and harder debugging.
3. Adding Hilt to a Compose project
A developer adds Hilt navigation or ViewModel dependencies from old tutorials. Those versions may not match the current Kotlin or Compose setup.
4. CI builds failing after dependency updates
Locally the code may seem fine, but the CI server performs a full clean build and exposes hidden version mismatches.
5. Maintaining legacy applications
Older apps often pin library versions for years. When one piece gets upgraded, several related dependencies must be updated together.
Real Codebase Usage
In real projects, developers usually handle this with version alignment and centralized dependency management.
Common patterns
1. Keep related tools on compatible versions
Developers group together versions for:
- Kotlin
- Android Gradle Plugin
- Hilt
- Room
- Compose
- Coroutines
This reduces random incompatibilities.
2. Use a single source of truth for versions
For example, in Gradle version catalogs or a centralized dependency file:
ext {
kotlin_version = "1.5.10"
hilt_version = "2.37"
}
Then use:
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
This avoids accidentally using different Hilt versions.
3. Apply guard-clause thinking to build maintenance
When upgrading Kotlin, developers immediately check:
- Is Hilt compatible?
- Is kapt still supported?
- Are AndroidX integration libraries still current?
4. Remove deprecated dependencies early
Old dependencies like com.android.support:* are often replaced quickly to reduce future migration problems.
5. Prefer stable versions over old alpha or beta versions
Using old alpha artifacts from tutorials can create hidden incompatibilities. In production codebases, stable versions are preferred whenever possible.
Common Mistakes
1. Upgrading Kotlin but not Hilt
This is the exact problem in the question.
Broken setup
ext.kotlin_version = "1.5.10"
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
Fix
Upgrade Hilt to a version compatible with Kotlin 1.5.10.
2. Mixing Hilt versions
Broken setup
implementation "com.google.dagger:hilt-android:2.40"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
Runtime and compiler versions should match.
Fix
implementation "com.google.dagger:hilt-android:2.40"
kapt "com.google.dagger:hilt-android-compiler:2.40"
3. Mixing very old AndroidX Hilt artifacts
Broken setup
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0-beta01"
Mixing old alpha and beta artifacts can cause additional compatibility problems.
Fix
Use matching and modern AndroidX Hilt artifacts, or remove old integrations if your current Hilt version already provides a better approach.
4. Keeping old support libraries in AndroidX projects
Comparisons
| Situation | What it means | Typical fix |
|---|---|---|
| Kotlin upgraded, Hilt unchanged | New metadata read by old processor | Upgrade Hilt |
| Hilt runtime and compiler versions differ | Generated code and runtime may be incompatible | Match versions exactly |
| Old support library used in AndroidX app | Legacy dependency setup | Replace with AndroidX equivalent |
| Old alpha/beta AndroidX Hilt artifacts | Integration libraries may not match newer Kotlin/Hilt | Use aligned, newer versions |
| IDE sync passes but build fails | Annotation processing fails later during kapt | Run a full clean build |
Hilt compatibility thinking
| Component | Role | Must be compatible with |
|---|
Cheat Sheet
// Good rule: align Kotlin and Hilt versions
ext.kotlin_version = "1.5.10"
ext.hilt_version = "2.37"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
Quick rules
- If you upgrade Kotlin, check Hilt compatibility.
- Keep
hilt-androidandhilt-android-compileron the same version. - Be careful with old alpha/beta AndroidX Hilt dependencies.
- Avoid mixing AndroidX with
com.android.support:*libraries. - Run a clean build after dependency changes.
Common fix checklist
- Upgrade Hilt from old versions like
2.33-beta - Match runtime and compiler versions
- Update or remove outdated AndroidX Hilt artifacts
- Replace:
implementation 'com.android.support:palette-v7:28.0.0'
with:
implementation 'androidx.palette:palette:1.0.0'
- Rebuild:
./gradlew clean build
Likely cause of this exact error
FAQ
Why does Hilt say "Unsupported metadata version"?
Because the Hilt compiler is trying to read Kotlin metadata produced by a newer Kotlin compiler version that it does not support.
Can I fix this without changing my Kotlin code?
Yes. This is usually a build dependency issue, not an app code issue.
Should hilt-android and hilt-android-compiler use the same version?
Yes. Keeping them on the same version is the safest and standard approach.
Is Kotlin 1.5.10 the problem by itself?
Not by itself. The problem is using Kotlin 1.5.10 with Hilt libraries that are too old.
Do old alpha AndroidX Hilt libraries matter?
Yes. Old integration artifacts can cause compatibility issues or make your dependency graph harder to maintain.
Does com.android.support:palette-v7 cause this exact Hilt error?
Usually no, but it signals that the project may contain outdated dependencies and should be modernized.
What is the simplest fix to try first?
Upgrade Hilt to a newer compatible version, keep runtime and compiler versions aligned, then run a clean build.
Mini Project
Description
Create a small Android dependency setup audit for a project that uses Kotlin and Hilt. The goal is to practice identifying version mismatches and replacing outdated dependencies before they cause build failures. This mirrors a real maintenance task that Android developers perform when upgrading libraries.
Goal
Review a Gradle setup, align Kotlin and Hilt versions, replace outdated dependencies, and produce a build configuration that is consistent and easier to maintain.
Requirements
- Define a single Kotlin version and a single Hilt version.
- Use the same Hilt version for both runtime and compiler dependencies.
- Replace any
com.android.supportdependency with an AndroidX equivalent. - Remove or update obviously outdated alpha/beta Hilt integration artifacts.
- Provide a Gradle dependency block that is internally consistent.
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.
Allow HTTP and HTTPS in Android 9 Pie with Network Security Configuration
Learn how Android 9 Pie handles cleartext HTTP traffic and how to allow HTTP and HTTPS safely using network security config.
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.