objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

Kotlin-Native support for multiplatform development

Open jittya opened this issue 7 years ago • 27 comments
trafficstars

Note: There is a helpful Stack Overflow response about this.


is there any way that i can use objectbox in kotlin native module and share the bussiness logics in android and ios modules ?

jittya avatar Nov 04 '18 04:11 jittya

This would require major changes, so it's nothing we could do on the fly. Let's see how many people would be interested in this.

greenrobot avatar Nov 04 '18 18:11 greenrobot

I don't think this is an objectbox issue. Objectbox is just an external library for the Android platform and it has to exist within an Android module, nothing can be shared on other platforms with regards to ObjectBox. You can, however, have a local data source interface for your models that will be implemented on each platform separately and ObjectBox will do that for the Android platform.

abdurahmanadilovic avatar Nov 07 '18 14:11 abdurahmanadilovic

I don't think this is an objectbox issue. Objectbox is just an external library for the Android platform and it has to exist within an Android module

The 4th item on objectbox.io is "cross platform", and supporting Kotlin/Native would allow using ObjectBox in cross platform projects, which is currently not possible without implementing a higher level abstraction layer.

It does seem like a major change, it would at least require converting all the java classes to kotlin, and in the native implementation, call the C library from kotlin instead of using JNI.

zydeco avatar Nov 20 '18 09:11 zydeco

is there an internal branch for this? can we make any contributions?

seyedjafariy avatar Jan 29 '19 08:01 seyedjafariy

Any update about this?

JavierSegoviaCordoba avatar Apr 13 '19 03:04 JavierSegoviaCordoba

Would love to have this

thanhhai08sk avatar Oct 31 '19 12:10 thanhhai08sk

It does seem like a major change, it would at least require converting all the java classes to kotlin, and in the native implementation, call the C library from kotlin instead of using JNI.

Very good observation. Because of that effort, we'll watch how much interest this feature request generates. With our limited resources, we will not start on this immediately though.

There is a theoretic approach using the C API with Kotlin MP, but that is won't be (as) pretty...

greenrobot avatar Oct 31 '19 12:10 greenrobot

It does seem like a major change, it would at least require converting all the java classes to kotlin, and in the native implementation, call the C library from kotlin instead of using JNI.

Very good observation. Because of that effort, we'll watch how much interest this feature request generates. With our limited resources, we will not start on this immediately though.

There is a theoretic approach using the C API with Kotlin MP, but that is won't be (as) pretty...

Has anyone attempted this?

CarsonRedeye avatar Sep 20 '20 05:09 CarsonRedeye

+1

atulgpt avatar Sep 30 '20 07:09 atulgpt

would also like to have this

Ditscheridou avatar Apr 21 '21 09:04 Ditscheridou

Any updates for this issue?

AronMitk avatar May 01 '21 20:05 AronMitk

Will be great to have this!

TomislavMladenov avatar Jul 04 '21 07:07 TomislavMladenov

It will be great to have support for kmm

TonnyL avatar Jul 30 '21 09:07 TonnyL

Yes please!

kihaki avatar Sep 19 '21 16:09 kihaki

+1

brandonpollack23 avatar Mar 11 '22 07:03 brandonpollack23

+1

galacticfungus avatar May 18 '22 03:05 galacticfungus

In the meantime Kotlin multiplatform gone beta :) Is there any update about support kmm for android and ios?

ArtemMikhaylov avatar Oct 23 '22 17:10 ArtemMikhaylov

@ArtemMikhaylov if you want you can try the new https://github.com/realm/realm-kotlin for the time being

jittyandiyan avatar Oct 23 '22 18:10 jittyandiyan

@jittyandiyan I checked it out. I used to work with realm in java android app about 2 years ago, and I liked it. But once I queried objects from realm, I used copyFromRealm function on them. So I could work in my logic with them as plane java objects. I like it this way. And it seems like in kotlin Realm for multiplatform it's not an option. So I decided to go with SQLDelight for now.

ArtemMikhaylov avatar Oct 24 '22 06:10 ArtemMikhaylov

It's nearly five years, and no progress. Now I realize that it's much better to use either flutter or leave ObjectBox. 😥

fcat97 avatar Jul 08 '23 16:07 fcat97

You have more alternatives for Multiplatform storage: Realm, Sqldelight, Datastore, Multiplatform Settings... No need for Flutter.

JavierSegoviaCordoba avatar Jul 08 '23 17:07 JavierSegoviaCordoba

@fcat97 Not Kotlin multi-platform, but ObjectBox is also available for Flutter.

Edit: There is also a helpful Stack Overflow response about this.

greenrobot-team avatar Jul 10 '23 06:07 greenrobot-team

Kotlin Multiplatform is now stable. I think, it's a huge opportunity for ObjectBox. Any storage option not supporting Kotlin Multiplatform will probably soon become irrelevant.

sebastianharder avatar Nov 02 '23 21:11 sebastianharder

I don't understand why it doesn't work. It works with Kotlin and JavaFX on all 3 Windows, Mac & Linux. Now I switch to Compose Multi and something breaks. ToMany & ToOne relationships are completely useless. I have managed to make them persist a little bit but then something breaks. Why is this? There is no hope for longevity. I am just going to have to ditch the relationships entirely since they don't persist. Might be slow but at least it'll work.

Just to clarify for anybody potentially reading this. ObjectBox does in fact work with Compose Multiplatform. It syncs, it persists regular entities and queries everything just fine. The only problem that I'm having is the ToMany & ToOne relationships are not working properly. I keep saving them and then I query them, but there's only 1 entity or none in the ToMany list. You even have to add some extra code for it to even work in the first place like the BoxStore inside the class and you have to attach the entity. It's just so odd. I really hope I can figure something out before switching databases entirely.

NobilityDeviant avatar Feb 26 '24 09:02 NobilityDeviant

@NobilityDeviant This is likely because the bytecode transformer included in the ObjectBox Gradle plugin does not run. It only works for Java JVM or Android projects. See https://docs.objectbox.io/relations#initialization-magic for details and maybe manual steps you can take.

greenrobot-team avatar Feb 26 '24 12:02 greenrobot-team

@NobilityDeviant This is likely because the bytecode transformer included in the ObjectBox Gradle plugin does not run. It only works for Java JVM or Android projects. See https://docs.objectbox.io/relations#initialization-magic for details and maybe manual steps you can take.

Sorry i was really upset the other night. I created some abstract entity system on top of objectbox and it turns out it was just my fault for not doing it properly. It's all working well now.

NobilityDeviant avatar Feb 27 '24 22:02 NobilityDeviant