Skip to content

[2.57] Module was compiled with an incompatible version of Kotlin #4848

Description

@AlexanderEggers

When trying to update to the latest Dagger/Hilt version 2.57, I get the following errors in my project:

e: file:///Users/alexandereggers/.gradle/caches/modules-2/files-2.1/com.google.dagger/hilt-android-gradle-plugin/2.57/e77a7c859d29dee90dab5b36fa9b5ff6971d498a/hilt-android-gradle-plugin-2.57.jar!/META-INF/main.kotlin_module Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.2.0, expected version is 2.0.0.
e: file:///Users/alexandereggers/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.2.0/fdfc65fbc42fda253a26f61dac3c0aca335fae96/kotlin-stdlib-2.2.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 2.2.0, expected version is 2.0.0.
e: file:///Users/alexandereggers/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.2.0/fdfc65fbc42fda253a26f61dac3c0aca335fae96/kotlin-stdlib-2.2.0.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.2.0, expected version is 2.0.0.
e: file:///Users/alexandereggers/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.2.0/fdfc65fbc42fda253a26f61dac3c0aca335fae96/kotlin-stdlib-2.2.0.jar!/META-INF/kotlin-stdlib.kotlin_module Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.2.0, expected version is 2.0.0.

AGP: 8.11.1
Kotlin: 2.2.0
Gradle Wrapper: 8.14.3

Let me know if you need any additional details about my project setup. I already tried to delete my gradle caches but no luck.

Activity

  1. NUmeroAndDev commented on Jul 22, 2025

    @NUmeroAndDev

    I'm facing same problem.
    My project uses Composite build, and it seems that Kotlin version used in Composite build is not the same as Kotlin version used in Hilt Plugin.

  2. danysantiago commented on Jul 22, 2025

    @danysantiago
    Member

    Hi - Can you double check which version of Kotlin you have in your 'buildSrc' project and in the other composite build projects?

    The error message seems to indicate that you are still in Kotlin 2.0.0, but Hilt has upgraded to 2.2.0.

  3. lsuski commented on Jul 22, 2025

    @lsuski

    The same on my project. I have kotlin 2.2.0 everywhere but it seems like Gradle and maybe kotlin-dsl plugin use kotlin 2.1.20. This is what I see from dependencies task. Maybe this is more like Gradle issue

  4. ArthurKun21 commented on Jul 23, 2025

    @ArthurKun21

    AGP: 8.11.0
    Kotlin: 2.2.0
    Gradle Wrapper: 8.14.1

    I've tried earlier Gradle 9.0.0 RC3 which has Kotlin 2.2 and it still failed

    https://github.com/gradle/gradle/releases/tag/v9.0.0-RC3

    https://docs.gradle.org/9.0.0-rc-3/release-notes.html

    edit:

    okay, I need to update to 9.0.0-RC3 first before updating the dagger hilt

  5. mar3kk commented on Jul 23, 2025

    @mar3kk

    Same issue here. Bumping Gradle to 9.0.0-rc-3 fixed this issue for me, but we don't wanna switch to it just yet.
    Asked this question on Gradle Slack: https://gradle-community.slack.com/archives/CAD95CR62/p1753211835993559
    Someone answered:

    The resolution is to ask dagger hilt to add apiVersion=1.8, languageVersion=apiVersion, and coreLibrariesVesion=1.8, so it supports backward compatibility

    Apparently it should also be possible to use kotlin("jvm") plugin instead of kotlin-dsl but I failed so far.

  6. alluhemanth commented on Jul 23, 2025

    @alluhemanth

    Apparently upgrading kotlin-dsl worked for me.

    AGP: 8.11.1
    Kotlin: 2.2.0
    Gradle Wrapper: 8.14.3

    And I changed from

    plugins {
        `kotlin-dsl`
    }

    to

    plugins {
        `kotlin-dsl` version "6.2.0"
    }
  7. mar3kk commented on Jul 23, 2025

    @mar3kk

    I eventually managed to migrate my plugin modules to use kotlin.jvm instead of kotlin-dsl plugin. Now they're decoupled from the Kotlin shipped with Gradle.
    Followed this great article: https://mbonnin.net/2025-07-10_the_case_against_kotlin_dsl/

  8. vlsi commented on Jul 23, 2025

    @vlsi

    In theory, a part of the build uses apiVersion and languageVersion:

    languageVersion.set(KotlinVersion.fromVersion(project.getVersionByName("kotlinTarget")))
    apiVersion.set(KotlinVersion.fromVersion(project.getVersionByName("kotlinTarget")))

    However, there are several issues still present:

    1. hilt-android-gradle-plugin misses that configuration, so it lacks apiVersion and languageVersion altogether:
      pluginArtifactId = 'hilt-android-gradle-plugin'
    2. DaggerConventionPlugin misses coreLibrariesVersion. It should be there so kotlin("jvm") configures a proper dependency on kotlin-stdlib-$target otherwise the added dependency would still refer a newer kotlin-stdlib. I think this block could be replaced with coreLibrariesVersion setting:
      afterEvaluate {
      dependencies {
      // This is needed to align older versions of kotlin-stdlib.
      // The main issue is that in v1.8.0 the jdk7 and jdk8 artifacts were
      // merged into kotlin-stdlib, so without this alignment we end up
      // getting duplicate classes by pulling in both artifacts.
      // See: https://kotlinlang.org/docs/whatsnew18.html#usage-of-the-latest-kotlin-stdlib-version-in-transitive-dependencies
      implementation(platform("org.jetbrains.kotlin:kotlin-bom:$kotlin_version"))
      }
    3. DaggerConventionPlugin does not properly configure Kotlin compiler to target Java 1.8. It should be using Xjdk-release=8 rather than jvmTarget. The difference is that Xjdk-release properly accounts for Java 1.8 public API. Currently, it looks like the build tries to use old JDK toolchain which might result in compilation failures. At best, the build should use the newest LTS compiler (e.g. Java 21) and it should target the desired release with javac --release and kotlinc -Xjdk-release.
  9. bcorso commented on Jul 29, 2025

    @bcorso

    This should be fixed at head.

    If someone could verify the fix with the HEAD-SNAPSHOT artifacts, that would be great. Otherwise, we'll try to do another release next week.

  10. alsutton commented on Jul 31, 2025

    @alsutton

    Are there some instructions on how to do that? Unfortunately our build system uses Gradle plugins, and a simple version bump ends up with;

    org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.dagger.hilt.android', version: 'HEAD-SNAPSHOT', apply: false] was not found in any of the following sources:
    
  11. bcorso commented on Jul 31, 2025

    @bcorso

    @alsutton Did you update your repositories to include the maven snapshots url?

        repositories {
            maven {
                url "https://central.sonatype.com/repository/maven-snapshots"
            }
        }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions