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

Kotlin 2.1.0 support #1857

Open
iXPert12 opened this issue Nov 28, 2024 · 49 comments
Open

Kotlin 2.1.0 support #1857

iXPert12 opened this issue Nov 28, 2024 · 49 comments

Comments

@iXPert12
Copy link

How frequently does the bug occur?

Always

Description

After update to kotlin 2.1.0, my project doesn't compile.

Stacktrace & log output

Caused by: java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.fir.types.ConeKotlinType org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.getType()'
	at io.realm.kotlin.compiler.IrUtilsKt.isBaseRealmObject(IrUtils.kt:229)
	at io.realm.kotlin.compiler.fir.model.CompanionExtension.getNestedClassifiersNames(CompanionExtension.kt:45)
	at org.jetbrains.kotlin.fir.scopes.impl.FirGeneratedMemberDeclarationsStorage.getClassifierStorage$providers(FirGeneratedScopes.kt:170)
	at org.jetbrains.kotlin.fir.scopes.impl.FirGeneratedClassNestedClassifierScope$Companion.create(FirGeneratedScopes.kt:126)

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

2.3.0

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Macos Sequoia 15.1

Build environment

Android Studio version: 2024.2.1
Android Build Tools version: ...
Gradle version: 8.10.2

@izadiegizabal
Copy link

same here :(

@Supereuro
Copy link

same here!

@promanowicz
Copy link

Bump, version 3.0.0 has the same issue

@hendydanakini
Copy link

same here with gradle 8.11.1 and agp 8.7.3

@vovan888
Copy link

vovan888 commented Dec 7, 2024

The same with realm-kotlin 3.0.0

@shalva97
Copy link

same issue here. Any plans to fix this?

@p-romanowicz
Copy link

p-romanowicz commented Dec 11, 2024

same issue here. Any plans to fix this?

Maybe @nhachicha would give an answer?

@Akshar062
Copy link

Guys, i have been using room for very small requirements but wanted to try realm is it worth it as it's documentation is very bad and it is not supporting kotlin 2.0 or higher

@vovan888
Copy link

vovan888 commented Dec 14, 2024

Looks like realm is not maintained anymore - #1852 (comment)

@shalva97
Copy link

shalva97 commented Dec 14, 2024

it is not supporting kotlin 2.0 or higher

it does support or at least works for me on Kotlin 2.0.21

Looks like realm is not maintained anymore

they say that it is minimum maintenance, maybe there are still some hopes? I'd rather switch to Room than maintain fork of realm

@abdou-gh549
Copy link

it doesn't work for me

@outer-worlds9423
Copy link

Same issue for me. Any word on this?

@SimonSchubert
Copy link

Is anyone here maintaining a fork with up to date dependencies? I'm very happy with realm and need no more features but don't want to stuck with an updated kotlin version

@XilinJia
Copy link

I looked in the code, there is this comment:

// This is the K2 equivalent of our PSI hack to determine if a symbol has a RealmObject base class.
// There is currently no way to determine this within the resolved type system and there is
// probably no such option around the corner.
// https://kotlinlang.slack.com/archives/C03PK0PE257/p1694599154558669

Tried to check about the link, but it requires an account in slack with an email address: @jetbrains.com

Don’t have an @jetbrains.com email address?
Contact the workspace administrator at kotlinlang for an invitation.

Not sure how to get it yet.

@XilinJia
Copy link

XilinJia commented Jan 20, 2025

it does support or at least works for me on Kotlin 2.0.21

Kotlin 2.0.20 works for me, just have trouble with Kotlin 2.1.0

@shalva97
Copy link

shalva97 commented Jan 20, 2025

Tried to check about the link, but it requires an account in slack with an email address: @jetbrains.com

You can join the slack via this survey https://surveys.jetbrains.com/s3/kotlin-slack-sign-up or you can see the messages here https://slack-chats.kotlinlang.org/t/15702763/hi-i-am-trying-to-update-a-compiler-plugin-with-k2-support-a without registration

@XilinJia
Copy link

from Comtributing.md:

This repository does currently not support building on Linux from the source code.

@matt18224
Copy link

Is anyone here maintaining a fork with up to date dependencies? I'm very happy with realm and need no more features but don't want to stuck with an updated kotlin version

I took a stab at it, but the Realm compiler uses a ton of internal Kotlin compiler functions/classes (not just the public APIs). Many of the internal code's signatures, visibilities, package names, and generic type parameters changed from 2.0.20 -> 2.1.0. The more I tried to change things to match the new signatures, the more things broke, and I don't know nearly enough about the internals of the Kotlin compiler to be able to say it was even done correctly with any level of confidence.

Mongo laid off their Realm leads and the devs were either also let go or reassigned, so probably no help from any of them anytime soon. Our only hope might be if someone from JetBrains who knows the Kotlin compiler inside and out decided to give it a try.

@XilinJia
Copy link

I just got it built on Linux with 2.0.20 but with gradle 8.11 and Java 17. Things appear OK so far. They didn't have Linux build scripts coded in, that's why they mentioned it's not supported?

I do see a couple messages like:

This will become an error in Kotlin 2.1.
w: realm-kotlin/packages/cinterop/src/commonMain/kotlin/io/realm/kotlin
/internal/interop/sync/AppError.kt:29:21 Non-public primary constructor is exposed via the generated 'copy()
' method of the 'data' class.

The generated 'copy()' will change its visibility in future releases.

I guess the major issue is still with the compiler plugins. I see that there are both frontend and backend plugins implemented. I haven't looked much in detail (and I don't have lots of internal knowledge of Kotlin), I'd suppose the frontends are easier issues than the backends.

@XilinJia
Copy link

Build with 2.0.21 on Linux appears also OK. Test outputs look the same as with 2.0.20, with the same errors:

Task :test-base:jvmTest

BacklinksTests[jvm] > unsupported types[jvm] FAILED
    java.lang.AssertionError at BacklinksTests.kt:51

BacklinksTests[jvm] > non parameter defined embedded objects[jvm] FAILED
    java.lang.AssertionError at BacklinksTests.kt:29

BacklinksTests[jvm] > non parameter defined[jvm] FAILED
    java.lang.AssertionError at BacklinksTests.kt:19

BacklinksTests[jvm] > unsupported types embedded objects[jvm] FAILED
    java.lang.AssertionError at BacklinksTests.kt:68

987 tests completed, 4 failed, 44 skipped

Anyone see these differently when building on the Mac, or take these as issues?

Next, will build with 2.1.0 and see what happens.

@XilinJia
Copy link

XilinJia commented Jan 23, 2025

Build with 2.1.0 got 55 build errors, but the good news is they are only restricted in 7 files. Error log is attached.

build_errors.log

@matt18224
Copy link

One issue I ran into was with the Gradle version. I got some errors after bumping to 2.1.0 that seemed to stem from the old versions of Gradle not playing well with the new version of Kotlin. When I bumped the Gradle version to the latest, it seemed to address it. I had to make some tweaks to the various build.gradle.kts files as well.

The one file in the Realm compiler that gave me particular issues was io.realm.kotlin.compiler.IrUtils.kt. It uses internal Kotlin compiler functions and classes whose signatures and visibilities changed in 2.1.0. So either the IrUtils.kt has to forcefully use the now internal Kotlin compiler classes and suppress the error with an @Suppress annotation (which feels really hacky) or be completely rewritten not to use that internal class (which seems like a major overhaul).

I wish you luck!

@XilinJia

This comment has been minimized.

@XilinJia
Copy link

XilinJia commented Jan 24, 2025

Looks like fundamentally fixed. 2.1.0 builds without problem. Also upped some dependencies.

All appears working the same way as the 2.0.x builds.

> Task :test-base:jvmTest

BacklinksTests[jvm] > unsupported types[jvm] FAILED
    java.lang.AssertionError at BacklinksTests.kt:51

BacklinksTests[jvm] > non parameter defined embedded objects[jvm] FAILED
    java.lang.AssertionError at BacklinksTests.kt:29

BacklinksTests[jvm] > non parameter defined[jvm] FAILED
    java.lang.AssertionError at BacklinksTests.kt:19

BacklinksTests[jvm] > unsupported types embedded objects[jvm] FAILED
    java.lang.AssertionError at BacklinksTests.kt:68

987 tests completed, 4 failed, 44 skipped

Will do some cleaning and push to my repository. Welcome any further testing.

@XilinJia
Copy link

XilinJia commented Jan 24, 2025

It's pushed to here: https://github.com/XilinJia/realm-kotlin

When you download, you need, as originally directed, git clone --recursive https://github.com/XilinJia/realm-kotlin.git . The packages/external/core points to a realm repository.

I'm not sure how to make it easy to use (I know it needs more testing now), as it's not on maven or anything, any suggestions.

@timonmw
Copy link

timonmw commented Jan 27, 2025

So there will not be an official update to support kotlin 2.1.0? I would really like to keep realm instead of sqlite, but its a dealbreaker when you are stuck with kotlin 2.0.21

@SanEffect
Copy link

@clementetb
Are there any rough timelines for when Kotlin 2.1.0 support will be added? We could consider rolling back to Kotlin 2.0.20 if we could expect support for 2.1.0 within the next 2-3 months. Otherwise, we may have to move away from Realm, which we would really prefer to avoid.

@PavelFedoseev
Copy link

It's pushed to here: https://github.com/XilinJia/realm-kotlin

When you download, you need, as originally directed, git clone --recursive https://github.com/XilinJia/realm-kotlin.git . The packages/external/core points to a realm repository.

I'm not sure how to make it easy to use (I know it needs more testing now), as it's not on maven or anything, any suggestions.

Thanks @XilinJia for the fix, I have tried to build it, but how can I publish to a test local repository with the correct version specified in Config,kt inside buildSrc.
Previously done by calling
./gradlew publishCIPackages -Prealm.kotlin.targets=jvm,android,compilerPlugin,gradlePlugin -Prealm.kotlin.buildRealmCore=true -Prealm.kotlin.mainHost=true
but now this task cannot be found

Currently root task publishToMavenLocal creates artifact with version: "unspecified" and group id: "realm-kotlin-root"

@XilinJia
Copy link

XilinJia commented Jan 28, 2025

@PavelFedoseev

3.2.1 should have fixed it (for JVM and android at least, I don't have macos, my MacBook pro was turned to a Linux machine).

I tweaked the project structure a bit in 3.2.0 to make intellij work (had it worked for anyone, on the Mac?). With that, what used to be run under packages, now need to be run in the root directory. I noted it in contributing.md

Let me know your experience.

Edit: @PavelFedoseev Re-reading your question, I can't say if 3.2.1 fixed your issue - I haven't used that command. If you reran it with 3.2.1, let me know the status.

@tinoue
Copy link

tinoue commented Jan 29, 2025

@XilinJia Nice work! I just had a quick glance at your commits. Are you keeping targetSdk = 33 (not 35) on purpose?

@XilinJia
Copy link

@XilinJia Are you keeping targetSdk = 33 (not 35) on purpose?

No, I didn't touch it, will make it to 35.

@PavelFedoseev
Copy link

@PavelFedoseev

3.2.1 should have fixed it (for JVM and android at least, I don't have macos, my MacBook pro was turned to a Linux machine).

I tweaked the project structure a bit in 3.2.0 to make intellij work (had it worked for anyone, on the Mac?). With that, what used to be run under packages, now need to be run in the root directory. I noted it in contributing.md

Let me know your experience.

Edit: @PavelFedoseev Re-reading your question, I can't say if 3.2.1 fixed your issue - I haven't used that command. If you reran it with 3.2.1, let me know the status.

@XilinJia I figure it out. I just added allprojects config to root build.gradle.kts

allprojects {
    version = Realm.version
    group = Realm.group

    // Define JVM bytecode target for all Kotlin targets
    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile> {
        compilerOptions {
            jvmTarget.set(JvmTarget.fromTarget(Versions.kotlinJvmTarget))
        }
    }
}

as it was in og branch. Then registered task publishCIPackages inside root build.gradle.kts

 register<Task>("publishCIPackages") {
        group = "Publishing"
        description = "Publish packages that has been configured for this CI node. See `gradle.properties`."

        // Figure out which targets are configured. This will impact which sub modules will be published
        val availableTargets = setOf(
            "iosArm64",
            "iosX64",
            "jvm",
            "macosX64",
            "macosArm64",
            "android",
            "metadata",
            "compilerPlugin",
            "gradlePlugin"
        )

        val mainHostTarget: Set<String> = setOf("metadata") // "kotlinMultiplatform"

        val isMainHost: Boolean = project.properties["realm.kotlin.mainHost"]?.let { it == "true" } ?: false

        // Find user configured platforms (if any)
        val userTargets: Set<String>? = (project.properties["realm.kotlin.targets"] as String?)
            ?.split(",")
            ?.map { it.trim() }
            ?.filter { it.isNotEmpty() }
            ?.toSet()

        userTargets?.forEach {
            if (!availableTargets.contains(it)) {
                project.logger.error("Unknown publication: $it")
                throw IllegalArgumentException("Unknown publication: $it")
            }
        }

        // Configure which platforms publications we do want to publish
        val publicationTargets = (userTargets ?: availableTargets).let {
            when (isMainHost) {
                true -> it + mainHostTarget
                false -> it - mainHostTarget
            }
        }

        publicationTargets.forEach { target: String ->
            when(target) {
                "iosArm64" -> {
                    dependsOn(
                        ":packages:cinterop:publishIosArm64PublicationToTestRepository",
                        ":packages:cinterop:publishIosSimulatorArm64PublicationToTestRepository",
                        ":packages:library-base:publishIosArm64PublicationToTestRepository",
                        ":packages:library-base:publishIosSimulatorArm64PublicationToTestRepository",
                        ":packages:library-sync:publishIosArm64PublicationToTestRepository",
                        ":packages:library-sync:publishIosSimulatorArm64PublicationToTestRepository",
                    )
                }
                "iosX64" -> {
                    dependsOn(
                        ":packages:cinterop:publishIosX64PublicationToTestRepository",
                        ":packages:library-base:publishIosX64PublicationToTestRepository",
                        ":packages:library-sync:publishIosX64PublicationToTestRepository",
                    )
                }
                "jvm" -> {
                    dependsOn(
                        ":packages:jni-swig-stub:publishAllPublicationsToTestRepository",
                        ":packages:cinterop:publishJvmPublicationToTestRepository",
                        ":packages:library-base:publishJvmPublicationToTestRepository",
                        ":packages:library-sync:publishJvmPublicationToTestRepository",
                    )
                }
                "macosX64" -> {
                    dependsOn(
                        ":packages:cinterop:publishMacosX64PublicationToTestRepository",
                        ":packages:library-base:publishMacosX64PublicationToTestRepository",
                        ":packages:library-sync:publishMacosX64PublicationToTestRepository",
                    )
                }
                "macosArm64" -> {
                    dependsOn(
                        ":packages:cinterop:publishMacosArm64PublicationToTestRepository",
                        ":packages:library-base:publishMacosArm64PublicationToTestRepository",
                        ":packages:library-sync:publishMacosArm64PublicationToTestRepository",
                    )
                }
                "android" -> {
                    dependsOn(
                        ":packages:jni-swig-stub:publishAllPublicationsToTestRepository",
                        ":packages:cinterop:publishAndroidReleasePublicationToTestRepository",
                        ":packages:library-base:publishAndroidReleasePublicationToTestRepository",
                        ":packages:library-sync:publishAndroidReleasePublicationToTestRepository",
                    )
                }
                "metadata" -> {
                    dependsOn(
                        ":packages:cinterop:publishKotlinMultiplatformPublicationToTestRepository",
                        ":packages:library-base:publishKotlinMultiplatformPublicationToTestRepository",
                        ":packages:library-sync:publishKotlinMultiplatformPublicationToTestRepository",
                    )
                }
                "compilerPlugin" -> {
                    dependsOn(
                        ":packages:plugin-compiler:publishAllPublicationsToTestRepository",
                        ":packages:plugin-compiler-shaded:publishAllPublicationsToTestRepository"
                    )
                }
                "gradlePlugin" -> {
                    dependsOn(":packages:gradle-plugin:publishAllPublicationsToTestRepository")
                }
                else -> {
                    throw IllegalArgumentException("Unsupported target: $target")
                }
            }
        }

seems to be working for me on linux

@XilinJia
Copy link

Anyone has knowledge about the Realm Core project? It appears still being updated. And there is a version 20 together with version 14, but version 20 doesn't seem to have new features announced. What are the differences? So the core is not deprecated as the SDK's? What are the thoughts of keeping the DB core alive but deprecating all the SDK's?

@XilinJia
Copy link

@PavelFedoseev so the publishCIPackages script you quoted is not in the main branch? where is it? the og branch?

@mohammadd-dev
Copy link

Hi
Please update dependencies.
I have compile error with this dependencies.

agp = "8.8.0"
kotlin = "2.1.0"
ksp = "2.1.0-1.0.29"
cdCoreVersion = "2.1.0-beta15"
cdKspVersion = "2.1.0-beta15"
realm = "3.0.0"
Android Studio Ladybug Feature Drop | 2024.2.2

org.jetbrains.kotlin.util.FileAnalysisException: Somewhere in file
.../app/build/generated/ksp/debug/kotlin/com/ramcosta/composedestinations/generated/destinations/EditAlbumDestination.kt: 
java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.fir.types.ConeKotlinType org.jetbrains.kotlin.fir.types.FirResolvedTypeRef.getType()'
at org.jetbrains.kotlin.util.AnalysisExceptionsKt.wrapIntoFileAnalysisExceptionIfNeeded(AnalysisExceptions.kt:62)

When change to this , it works

agp = "8.8.0"
kotlin = "2.0.21"
ksp = "2.0.21-1.0.28"
cdCoreVersion = "2.1.0-beta15"
cdKspVersion = "2.1.0-beta15"
realm = "3.0.0"
Android Studio Ladybug Feature Drop | 2024.2.2

Just change ksp,kotlin version

@p-romanowicz
Copy link

It's pushed to here: https://github.com/XilinJia/realm-kotlin

When you download, you need, as originally directed, git clone --recursive https://github.com/XilinJia/realm-kotlin.git . The packages/external/core points to a realm repository.

I'm not sure how to make it easy to use (I know it needs more testing now), as it's not on maven or anything, any suggestions.

@XilinJia DId you think about creating a pull request to main repo?

@XilinJia
Copy link

@XilinJia DId you think about creating a pull request to main repo?

I thought the deprecation message is very clear: the project will be solely at the disposal of the community. So, to your question, no. But I'd happy to do if officially requested.

@ithersta
Copy link

ithersta commented Feb 11, 2025

I thought the deprecation message is very clear: the project will be solely at the disposal of the community. So, to your question, no. But I'd happy to do if officially requested.

@XilinJia They still accept PRs to the community branch #1858 (comment)

@XilinJia
Copy link

XilinJia commented Feb 11, 2025

They still accept PRs to the community branch #1858 (comment)

Thanks. I will check about filing a PR to the community branch.

@XilinJia
Copy link

PR is submitted here: #1860 (comment)

@XilinJia
Copy link

According to this experience: #1852 (comment), I'm not sure if the PR will likely be incorporated any time soon or at all.

@p-romanowicz
Copy link

Please @clementetb @nhachicha @cmelchior, any input?
I think community would appreciate.

@kerimovscreations
Copy link

Realm version 3.0.0 works fine with kotlin version 2.0.20, fyi anyone looks for quick fix

@sbenmeddour
Copy link

Realm version 3.0.0 works fine with kotlin version 2.0.20, fyi anyone looks for quick fix

Issue talks about Kotlin 2.1.0

@SimonSchubert
Copy link

@XilinJia is your version 3.2.2 accessible via maven or how would I use it?

@XilinJia
Copy link

XilinJia commented Feb 28, 2025

@XilinJia is your version 3.2.2 accessible via maven or how would I use it?

Not yet, but it appears better that I upload it to maven. Will try that shortly.

@SimonSchubert
Copy link

@XilinJia is your version 3.2.2 accessible via maven or how would I use it?

Not yet, but it appears better that I upload it to maven. Will try that shortly.

That would help me and others a lot. You are amazing thank you

@XilinJia
Copy link

XilinJia commented Mar 2, 2025

@XilinJia is your version 3.2.2 accessible via maven or how would I use it?

Not yet, but it appears better that I upload it to maven. Will try that shortly.

That would help me and others a lot. You are amazing thank you

Thank you for your appreciation.

Well, publishing to maven appears more complicated than I thought. The terms of the Apache license and the group id at maven all require io.realm to be rebranded. Or does anyone have a different understanding?

@XilinJia
Copy link

XilinJia commented Mar 3, 2025

first push of the rebranding is here: https://github.com/XilinJia/krdb

Looking to resolve some upload issue with maven central.

In the meantime, if you clone this project, you can publish to local maven from the root directory with:
./gradlew publishToMavenLocal
you should be able to use it with (in Android):

repositories {
    mavenLocal()
    mavenCentral()
}

and something like:
implementation("io.github.xilinjia.krdb:library-base:3.2.3-SNAPSHOT")

I'd like to hear if there are issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests