realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
906 stars 52 forks source link

Possibility to have realm-kotlin and realm-jvm in same project #280

Closed tarasmorskyi-mediamonks closed 2 years ago

tarasmorskyi-mediamonks commented 3 years ago

When some library (like Lokalise) is using realm-jvm under the hood it becomes impossible to use due to conflict between library and kmm modules which use realm-kotlin. Sample error log:

Duplicate class io.realm.BaseRealm found in modules jetified-library-debug-runtime (io.realm.kotlin:library-android-debug:0.1.0) and jetified-realm-android-library-10.0.0-runtime (io.realm:realm-android-library:10.0.0)
Duplicate class io.realm.BuildConfig found in modules jetified-library-debug-runtime (io.realm.kotlin:library-android-debug:0.1.0) and jetified-realm-android-library-10.0.0-runtime (io.realm:realm-android-library:10.0.0)
Duplicate class io.realm.Realm found in modules jetified-library-debug-runtime (io.realm.kotlin:library-android-debug:0.1.0) and jetified-realm-android-library-10.0.0-runtime (io.realm:realm-android-library:10.0.0)
Duplicate class io.realm.RealmConfiguration found in modules jetified-library-debug-runtime (io.realm.kotlin:library-android-debug:0.1.0) and jetified-realm-android-library-10.0.0-runtime (io.realm:realm-android-library:10.0.0)
Duplicate class io.realm.RealmConfiguration$Builder found in modules jetified-library-debug-runtime (io.realm.kotlin:library-android-debug:0.1.0) and jetified-realm-android-library-10.0.0-runtime (io.realm:realm-android-library:10.0.0)
Duplicate class io.realm.RealmObject found in modules jetified-library-debug-runtime (io.realm.kotlin:library-android-debug:0.1.0) and jetified-realm-android-library-10.0.0-runtime (io.realm:realm-android-library:10.0.0)
Duplicate class io.realm.RealmResults found in modules jetified-library-debug-runtime (io.realm.kotlin:library-android-debug:0.1.0) and jetified-realm-android-library-10.0.0-runtime (io.realm:realm-android-library:10.0.0)
Duplicate class io.realm.log.LogLevel found in modules jetified-library-debug-runtime (io.realm.kotlin:library-android-debug:0.1.0) and jetified-realm-android-library-10.0.0-runtime (io.realm:realm-android-library:10.0.0)
Duplicate class io.realm.log.RealmLogger found in modules jetified-library-debug-runtime (io.realm.kotlin:library-android-debug:0.1.0) and jetified-realm-android-library-10.0.0-runtime (io.realm:realm-android-library:10.0.0)

Possible solution: have different package name for realm-kotlin like io.realm.kotlin

rorbech commented 3 years ago

We foresee quite some challenges in ensuring that the two libraries will be able to coexist even if we resolve the JVM package naming, but thanks for the input. We will have it in mind.

tarasmorskyi-mediamonks commented 2 years ago

Any updates on this?

rorbech commented 2 years ago

In Realm Kotlin we are relying on the same native implementation of the core database and there is no options for two different version coexist in the same process address space, so this will not be possible unless addressed natively. There is not any plan of doing that right now.

tarasmorskyi-mediamonks commented 2 years ago

Yes, I understand about native implementation but issue lays on the ∆ava/Kotlin layer as you use the same package name for both Realm-Android and Realm-Kotlin. It you will have something like io.realm.kotlin for Realm-Kotlin and io.realm for Realm-Android it will solve this issue. Of course it may require some alignments in versions to use the same or compatible NDK package.

rorbech commented 2 years ago

The problem is that the native parts are not exactly the same, so we cannot just reuse the so-file in both SDKs. And as said, aligning them or finding a way where the two different versions can coexist is not on our current roadmap.

The obvious thing to do would be to migrate old libraries to Realm Kotlin when the required feature set is supported. Then it would just be a matter of aligning the versions in the dependencies.

tarasmorskyi-mediamonks commented 2 years ago

Oh, makes sense now. I was expecting usage of the same native parts and KMM being only a middleware for single codebase.