Fixing "Provided Metadata instance has version 2.1.0" Build Error in Flutter
Problem Statement
When building an Android APK generated with Flutter, you may encounter the following critical error:
ERROR: R8: java.lang.IllegalArgumentException:
Provided Metadata instance has version 2.1.0,
while maximum supported version is 2.0.0.
To support newer versions, update the kotlinx-metadata-jvm library.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
Compilation failed to complete
This error occurs due to version incompatibility between Kotlin libraries in your Android build pipeline. Specifically:
- Your project uses Kotlin 2.1.0 (or newer) components
- The
kotlinx-metadata-jvm
library in your build environment only supports up to version 2.0.0 - The R8 compiler fails during code minification due to this mismatch
Common causes include:
- Outdated Android Gradle Plugin (AGP)
- Incompatible Kotlin Gradle plugin versions
- Missing updates to supporting libraries like Hilt
- Gradle wrapper version conflicts
Recommended Solutions
1. Update Android Gradle Plugin and Gradle Wrapper (Recommended)
Modify settings.gradle
:
plugins {
id "com.android.application" version "8.6.0" apply false
// ... other plugins ...
}
Update Gradle Wrapper (gradle-wrapper.properties
):
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
```diff
::: tip Why this works
Newer AGP versions (8.6.0+) include updated `kotlinx-metadata-jvm` dependencies that support Kotlin 2.1.0+ metadata formats. Upgrading Gradle ensures compatibility with the latest Android tooling.
:::
### 2. Update Kotlin Gradle Plugin
Modify your `settings.gradle` to reference a **Kotlin plugin version ≥ 2.1.0**:
```gradle{6}
plugins {
// ... other plugins ...
id "org.jetbrains.kotlin.android" version "2.1.0" apply false
}
Important
Only perform this after upgrading AGP to 8.5.2+ to avoid compatibility issues.
3. Add kotlinx-metadata-jvm Dependency (Alternative)
In your app-level build.gradle
:
dependencies {
// Add anywhere in dependencies block
runtimeOnly("org.jetbrains.kotlin:kotlinx-metadata-jvm:0.9.0")
}
::: note When to use this Reserve this for temporary fixes if AGP updates are not immediately feasible. Prefer primary solutions for long-term stability. :::
4. Update Hilt Dependency (If Using Hilt)
For projects using Dependency Injection with Hilt:
// Top-level build.gradle
dependencies {
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.56.1'
}
Verification Steps
After implementing any solution:
- Clean your build artifacts:
flutter clean
- Regenerate dependencies:
flutter pub get
- Rebuild your APK:
flutter build apk
Solution Comparison
Approach | Stability | Longevity | Complexity |
---|---|---|---|
AGP + Gradle Upgrade ★ | High | Long-term solution | Moderate |
Kotlin Plugin Update | Medium | Requires AGP sync | Simple |
kotlinx-metadata-jvm Entry | Medium | Temporary workaround | Simple |
Hilt Update | Situational | Only if using Hilt | Simple |
Avoid Downgrading Kotlin
Downgrading Kotlin (e.g., to 2.0.0) may resolve the immediate error but often introduces new compatibility issues with modern Flutter plugins and Kotlin libraries.
Version mismatches in the Kotlin build chain frequently cause this error during Android release builds. The recommended solution is updating both Android Gradle Plugin and Gradle wrapper to their latest compatible versions, ensuring all tooling components support newer Kotlin metadata formats. Since the Flutter ecosystem evolves rapidly, maintaining updated build dependencies prevents similar issues with future Kotlin releases.