Skip to content

"Cannot inline bytecode" error in KMP project module #736

Open
@tellypresence

Description

@tellypresence

(Note: this is not a project bug, just a fix for a nasty error encountered during use that others may run into; leaving breadcrumbs here in case anyone else is looking for answers)

If you are using gitlive firebase in a KMP (Kotlin Multiplatform) project module and your (android) build breaks with error e.g.

Cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. 
Specify proper '-jvm-target' option.

the fix consists of 2 things:

  • Add jvmToolchain in kotlin block of build.gradle.kts
  • Check for installed JDK 17 and if not present, download and install

The usual workflow of setting JDK version in android studio "Project Structure" settings isn't supported for KMP modules; for kmp module the solution should be as simple as adding jvmToolchain() in kotlin block in build.gradle.kts

kotlin {
    jvmToolchain(17)

Also run this command in terminal (Android Studio terminal should work fine)

/usr/libexec/java_home -V

If JDK 17 not displayed in command output, download from e.g. oracle and install; should be picked up without any further steps required

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