Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realm incompatible with Kotlin projects compiled against a Java version newer than 8 #887

Closed
jakobkmar opened this issue Jun 12, 2022 · 6 comments
Labels
Needs-Attention Reporter has responded. Review comment. O-Community

Comments

@jakobkmar
Copy link

jakobkmar commented Jun 12, 2022

Cause:

Because of this, Realm is incompatible with other Kotlin libraries which have been built targetting a newer JVM version - since it is impossible to inline functions from these libraries then.

I don't think the Realm Gradle plugin should force all compilations to target JVM 1.8, right?

The temporary workaround to overwrite what the Realm Gradle plugin set here is the following:

project.afterEvaluate {
    kotlin.target.compilations.all { // use targets if this is a Multiplatform project
        kotlinOptions.jvmTarget = "17"
    }
}
@rorbech
Copy link
Contributor

rorbech commented Jun 28, 2022

@jakobkmar Thanks for the report and temporary workaround. We will investigate how to enforce our minimal required version along with working with other libraries. Do you mind sharing any immediate combination of libraries/setup that triggers this?

@edualonso edualonso added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Jul 11, 2022
@jakobkmar
Copy link
Author

Sorry for the late reply!

You simply have to find a library which has been compiled targetting a more recent Java version than 8 and try using an inline function from that library. I currently do not know any lightweight library which I can recommend for quickly testing this - but if you really need it I can search for one.

However creating a very simple one with one inline function taking a lambda parameter and publishing it to Maven Local and then adding it to a realm project is enough to trigger this issue.

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Jul 22, 2022
@anton-avm
Copy link

anton-avm commented Mar 22, 2023

Thanks a lot for the workaround. It's a lifesaver!

I have faced the same problem with my stack: Compose (which requires JVM 11) + Koin (using reified inline functions to provide dependencies) + Realm.

Also, I noticed that the workaround looks like an extension-based solution. I rewrote it a bit:

project.afterEvaluate {
    kotlin.targets.all {
        compilations.all {
            (kotlinOptions as? org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions)?.jvmTarget = "11"
        }
    }
}

@ghost
Copy link

ghost commented Apr 26, 2023

I ran into this issue while implementing: Nordic's BLE Library and got the error on asValidResponseFlow() off of setNotificationCallback.

I can confirm the above fix allows my code to once again compile.

@amadeuszblanik
Copy link

Is there an update on this issue? The workaround is effective for me, but it remains just that — a workaround

@rorbech
Copy link
Contributor

rorbech commented Nov 9, 2023

This is fixed by #1513 available from the 1.12.0 release.

@rorbech rorbech closed this as completed Nov 9, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs-Attention Reporter has responded. Review comment. O-Community
Projects
None yet
Development

No branches or pull requests

5 participants