Skip to content

Kotlin 2.1.0 support #1857

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

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

Kotlin 2.1.0 support #1857

iXPert12 opened this issue Nov 28, 2024 · 76 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 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.

@SimonSchubert
Copy link

SimonSchubert commented Mar 5, 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.

thanks again for your hard work!

that's how far I got on macos. haven't tried on liunux yet:

* What went wrong:
Could not create task ':packages:gradle-plugin:versionConstants'.
> .../krdb/packages/external/core/dependencies.yml (No such file or directory)
./gradlew publishToMavenLocal 


> Configure project :buildSrc
WARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `2.0.21` that might work differently than in the requested version `2.1.0`.

> Configure project :packages:cinterop
w: The artifact `org.jetbrains.kotlin:kotlin-compiler-embeddable` is present in the build classpath along Kotlin Gradle plugin.
This may lead to unpredictable and inconsistent behavior.
For more details, see: https://kotl.in/gradle/internal-compiler-symbols

Warning: Errors during XML parse:
Warning: Additionally, the fallback loader failed to parse the XML.
Checking the license for package NDK (Side by side) 27.0.12077973 in /Users/simon/Library/Android/sdk/licenses
License for package NDK (Side by side) 27.0.12077973 accepted.
Preparing "Install NDK (Side by side) 27.0.12077973 v.27.0.12077973".
"Install NDK (Side by side) 27.0.12077973 v.27.0.12077973" ready.
Installing NDK (Side by side) 27.0.12077973 in /Users/simon/Library/Android/sdk/ndk/27.0.12077973
"Install NDK (Side by side) 27.0.12077973 v.27.0.12077973" complete.
"Install NDK (Side by side) 27.0.12077973 v.27.0.12077973" finished.

> Configure project :packages:gradle-plugin
w: The artifact `org.jetbrains.kotlin:kotlin-compiler-embeddable` is present in the build classpath along Kotlin Gradle plugin.
This may lead to unpredictable and inconsistent behavior.
For more details, see: https://kotl.in/gradle/internal-compiler-symbols

w: file:///Users/simon/Projects/realm-cline/krdb/packages/gradle-plugin/build.gradle.kts:96:26: 'getter for buildDir: File!' is deprecated. Deprecated in Java
w: file:///Users/simon/Projects/realm-cline/krdb/packages/gradle-plugin/build.gradle.kts:104:36: 'create(String!, Action<in Task!>!): Task!' is deprecated. Deprecated in Java

[Incubating] Problems report is available at: ..../krdb/build/reports/problems/problems-report.html

FAILURE: Build failed with an exception.

* Where:
Build file '.../packages/gradle-plugin/build.gradle.kts' line: 104

* What went wrong:
Could not create task ':packages:gradle-plugin:versionConstants'.
> .../krdb/packages/external/core/dependencies.yml (No such file or directory)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.12/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 1m 47s

@XilinJia
Copy link

XilinJia commented Mar 5, 2025

@SimonSchubert seems to me that you didn't do:
git clone --recursive https://github.com/XilinJia/krdb.git
I updated more details in the readme.

@SimonSchubert
Copy link

@SimonSchubert seems to me that you didn't do: git clone --recursive https://github.com/XilinJia/krdb.git I updated more details in the readme.

Nice it looks like it's working for android 👍 not for my multiplatform (android/ios) project as you suggested already before

@XilinJia
Copy link

XilinJia commented Mar 5, 2025

not for my multiplatform (android/ios) project as you suggested already before

I don't have a way to test on ios or macos. Do you have more details when it doesn't work? What happens when you do:
./gradlew jvmTest connectedAndroidTest macosTest iosTest

@SimonSchubert
Copy link

SimonSchubert commented Mar 5, 2025

not for my multiplatform (android/ios) project as you suggested already before

I don't have a way to test on ios or macos. Do you have more details when it doesn't work? What happens when you do: ./gradlew jvmTest connectedAndroidTest macosTest iosTest

this is failing for me when I call ./gradlew publishToMavenLocal :

> Task :packages:cinterop:capiMacosUniversal
-- CMake version: 3.31.6
-- The C compiler identification is AppleClang 16.0.0.16000026
-- The CXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
CMake Error at /opt/homebrew/share/cmake/Modules/CMakeDetermineCompilerABI.cmake:129 (message):
  The C compiler targets architectures:

    "arm64"

  but CMAKE_OSX_ARCHITECTURES is

    "x86_64;arm64"

Call Stack (most recent call first):
  /opt/homebrew/share/cmake/Modules/CMakeTestCCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)
  CMakeLists.txt:5 (project)


-- Configuring incomplete, errors occurred!

> Task :packages:cinterop:capiMacosUniversal FAILED

when I try to add the realm dependency to my shared module it doesn't seem to find any ios realm dependencies

@XilinJia
Copy link

XilinJia commented Mar 5, 2025

Can't say much about MacOS, but it's likely your CMake issue? Did you check about system requirements in Contributing.md?

@SimonSchubert
Copy link

Can't say much about MacOS, but it's likely your CMake issue? Did you check about system requirements in Contributing.md?

system requirements look fine. I will give it another try tomorrow

@SuperCaliMan
Copy link

Hi! I've tested this on both android and iphone. To fix the issue mentioned by @SimonSchubert i removed x86_64 in cinterop/build.gradle.kts "-DCMAKE_OSX_ARCHITECTURES=arm64". After that, I was able to successfully build and publish the library on my mac M1 MAX. I've found that to enable cross compiling on MAC with ARM, one should add set(CMAKE_OSX_ARCHITECTURES "x86_64") to the Cmake files. I haven't tried this solution solution, yet.

@hansfritzi
Copy link

I had to add the dependencies for all the mac platforms to the build.gradle in the cinterop module to make it for for ios/macos

afterEvaluate {
    tasks.getByName("sourcesJar").dependsOn(generateSdkVersionConstant)
    tasks.named("androidReleaseSourcesJar") {
        dependsOn("generateSdkVersionConstant")
    }
    tasks.named("jvmSourcesJar") {
        dependsOn("generateSdkVersionConstant")
    }
    tasks.named("iosArm64SourcesJar") {
        dependsOn("generateSdkVersionConstant")
    }
    tasks.named("iosSimulatorArm64SourcesJar") {
        dependsOn("generateSdkVersionConstant")
    }
    tasks.named("iosX64SourcesJar") {
        dependsOn("generateSdkVersionConstant")
    }
    tasks.named("macosArm64SourcesJar") {
        dependsOn("generateSdkVersionConstant")
    }
    tasks.named("macosX64SourcesJar") {
        dependsOn("generateSdkVersionConstant")
    }
}

@XilinJia
Copy link

XilinJia commented Mar 7, 2025

Does Android work for everyone? I got it working and build a release Android app with the local maven. But I'm having trouble to reproduce that. Somehow, the newly built maven artifacts contains a librealmc.so that misses lots of symbols with RealmJNI for Android, and the Android app crashes just after start. I can't figure out what the issue is yet.

@hansfritzi
Copy link

I am currently getting

 `java.lang.UnsatisfiedLinkError: No implementation found for long io.realm.kotlin.internal.interop.realmcJNI.RLM_INVALID_CLASS_KEY_get() (tried Java_io_realm_kotlin_internal_interop_realmcJNI_RLM_1INVALID_1CLASS_1KEY_1get and Java_io_realm_kotlin_internal_interop_realmcJNI_RLM_1INVALID_1CLASS_1KEY_1get__) - is the library loaded, e.g. System.loadLibrary?

@XilinJia is this the same error you get?

@XilinJia
Copy link

XilinJia commented Mar 7, 2025

I am currently getting

 `java.lang.UnsatisfiedLinkError: No implementation found for long io.realm.kotlin.internal.interop.realmcJNI.RLM_INVALID_CLASS_KEY_get() (tried Java_io_realm_kotlin_internal_interop_realmcJNI_RLM_1INVALID_1CLASS_1KEY_1get and Java_io_realm_kotlin_internal_interop_realmcJNI_RLM_1INVALID_1CLASS_1KEY_1get__) - is the library loaded, e.g. System.loadLibrary?

@XilinJia is this the same error you get?

Yes, precisely. I can't understand what's happening. I had built 3.2.3 (at least before pushing to github) and that worked. I still have the apk, once unzipped having the librealmc.so containing the symbol realmcJNI. Now, I tried to build multiple times various versions 3.2.4, 3.2.3 rebuilt, and even the not-rebranded https://github.com/XilinJia/realm-kotlin. The librealmc.so in ~/.m2/repository/xxx/cinterop-android/xxx/cinterop-android-xxx.aar all lack the symbol. I can't figure out why. Seems the only change I haven't tested since I first built 3.2.3 is a system upgrade of Manjaro Linux (but how can that change it?)

What's your situation @hansfritzi

@hansfritzi
Copy link

hansfritzi commented Mar 7, 2025

I use Mac OS 15.3.1 and the not-rebranded version because i have some conflicts in my project that i wanted to override.
I could not find the problem but when i do a clean, then run the unit tests and then publishToMavenLocal it works for me.
When i set the property realm.kotlin.buildRealmCore to true it seems to work every time

@XilinJia
Copy link

XilinJia commented Mar 7, 2025

when i do a clean, then run the unit tests and then publishToMavenLocal it works

This is amazing. Thank you! @hansfritzi I spent more than a day with:

./gradlew clean publishToMavenLocal

only to fail at the Android app. realm.kotlin.buildRealmCore is already set to true in files.

Will find out why publishToMavenLocal doesn't trigger full build for Android.

@XilinJia
Copy link

XilinJia commented Mar 7, 2025

krdb is finally published to maven central. For descriptions, see: https://github.com/XilinJia/krdb

@AlexKatonaVisma
Copy link

Hey @XilinJia, really appreciate the efforts, but wanted to ask if you are also planning to sign the CLA ? mentioned in #1860. While its a good approach to fork and fix it, it seems like a more temporary than longer term solution and keeping up the community branch in the realm repository seems like the best approach maintance wise in long term.

@XilinJia
Copy link

I asked the question if the CLA is needed for the community branch as I thought it's not necessary. @AlexKatonaVisma, are you the maintainer of the repo and ready to merge the PR just waiting for me CLA? If that case, I'd be happy to do.

@AlexKatonaVisma
Copy link

AlexKatonaVisma commented Mar 18, 2025

I asked the question if the CLA is needed for the community branch as I thought it's not necessary. @AlexKatonaVisma, are you the maintainer of the repo and ready to merge the PR just waiting for me CLA? If that case, I'd be happy to do.

@XilinJia , no I am just a disappointed Realm user. But maybe one of the top contributors could help there? @cmelchior @rorbech @clementetb @nhachicha ?

@kzotin
Copy link

kzotin commented Mar 18, 2025

Given that mine PR (#1851) with CLA is still not merged / released, and last release happened 6 month ago -- I wouldn't expect active realm maintenance.

We maintain our own fork for now, and gradually migrating to room

@raquezha
Copy link

Any update on this?

@EranBoudjnah
Copy link

krdb has bugs too. As far as I can see, there's no easy way out of this. I'm going to have to downgrade my project, migrate all users to another persistence solution and eventually remove it entirely.

@SimonSchubert
Copy link

@EranBoudjnah I migrated a major multiplatform project from realm to room a few weeks ago. got it all working but just to find out that certain implementations didn't work well when I copied them 1 to 1 from realm to room. couldn't afford to spend any more time on it and reverted back to realm

@AlexKatonaVisma
Copy link

The best long term solution is to migrate away from Realm, we decided to do that recently and migrating it with the help of AI agent, it works great so far

@EranBoudjnah
Copy link

@EranBoudjnah I migrated a major multiplatform project from realm to room a few weeks ago. got it all working but just to find out that certain implementations didn't work well when I copied them 1 to 1 from realm to room. couldn't afford to spend any more time on it and reverted back to realm

In the long term none of us have a choice if we want to keep updating our Kotlin versions.

@nabahool
Copy link

nabahool commented Apr 8, 2025

Migrated to Room as well. It was easier than I thought, even though I had to reimplement some of the old stuff

StringMeUp pushed a commit to StringMeUp/KMPStarter that referenced this issue Apr 9, 2025
DI (Koin)
Threading (Coroutines)
Settings/User Defaults (Prefs)
Navigation (Voyager)
Networking (Ktor)
DateTime (DateTime)
Realm (Unmaintained works only with kotlin 2.0.20 realm/realm-kotlin#1857"
StringMeUp pushed a commit to StringMeUp/KMPStarter that referenced this issue Apr 9, 2025
DI (Koin)
Threading (Coroutines)
Settings/User Defaults (Prefs)
Navigation (Voyager)
Networking (Ktor)
DateTime (DateTime)
Realm (Unmaintained works only with kotlin 2.0.20
Check: realm/realm-kotlin#1857"
@rajeshct
Copy link

rajeshct commented May 7, 2025

Is there a strategy or solution in place to address this issue?

@sbenmeddour
Copy link

No you have to fork the repo

  • FInd a way to build it (good luck)
  • update kotlin version
  • fix compilation issues
  • publish to maven local

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