Skip to content
Cannot inline bytecode built with JVM target ...

Cannot inline bytecode built with JVM target ...

DodaTech 2 min read

The “Cannot inline bytecode built with JVM target” error means a Kotlin inline function and its call site were compiled targeting different JVM versions.

What It Means

Inline functions in Kotlin are expanded at the call site by copying their bytecode. When the caller and the callee were compiled targeting different JVM versions, the bytecode structures (class file format, method signatures) may be incompatible. The Kotlin compiler detects this mismatch and refuses to inline, showing the JVM targets of both sides.

Why It Happens

  • Your project uses jvmTarget = "1.8" but a dependency was compiled with jvmTarget = "17".
  • Different Gradle modules in a multi-module project have different jvmTarget values.
  • You upgraded your JDK but didn’t update jvmTarget in build.gradle.kts.
  • A library (e.g., Kotlinx coroutines) was compiled with a newer JVM target than your project.
  • The Kotlin compiler version differs between modules or dependencies.

How to Fix It

1. Set a consistent jvmTarget across all modules

// In each module's build.gradle.kts:
kotlin {
    jvmToolchain(17)
    // or
    jvmTarget = "17"
}

2. Set it globally in the root project

// In root build.gradle.kts — applies to all subprojects:
subprojects {
    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
        kotlinOptions.jvmTarget = "17"
    }
}

3. Use Java toolchains to auto-detect the JDK

// build.gradle.kts
kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}

4. Check your Kotlin compiler version

// build.gradle.kts — ensure all modules use the same Kotlin version
plugins {
    kotlin("jvm") version "2.0.0" // same version everywhere
}

// Check the wrapper
// gradle-wrapper.properties: kotlin.version must match

5. Clean and rebuild after changing targets

# Clear all cached bytecode and recompile
./gradlew clean build

If you use IntelliJ, also invalidate caches: File → Invalidate Caches and Restart.

6. Check transitive dependencies

Some libraries publish artifacts compiled with different JVM targets. Examine your dependency tree:

./gradlew dependencies

If a dependency is compiled for JVM 1.8 and your project targets JVM 17, the inline function from that dependency will trigger this error. In that case, update the dependency to a version compiled for your JVM target.

What JVM target should I use?
Use the lowest JVM version you need to support. If you target JDK 17+, set jvmTarget = "17". For Android projects, jvmTarget = "1.8" is common. All modules and dependencies should use the same value.
Does this error affect non-inline functions?
No — only inline functions require bytecode copying. Regular function calls work across different JVM targets as long as the class file format is compatible. The error is specific to Kotlin’s inline mechanism.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro