objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.41k stars 304 forks source link

Kotlin-Native support for multiplatform development #601

Open jittya opened 6 years ago

jittya commented 6 years ago

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 ?

greenrobot commented 6 years ago

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.

abdurahmanadilovic commented 6 years ago

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.

zydeco commented 6 years ago

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.

seyedjafariy commented 5 years ago

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

JavierSegoviaCordoba commented 5 years ago

Any update about this?

thanhhai08sk commented 5 years ago

Would love to have this

greenrobot commented 5 years ago

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...

CarsonRedeye commented 4 years ago

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?

atulgpt commented 4 years ago

+1

Ditscheridou commented 3 years ago

would also like to have this

AronMitk commented 3 years ago

Any updates for this issue?

TomislavMladenov commented 3 years ago

Will be great to have this!

TonnyL commented 3 years ago

It will be great to have support for kmm

kihaki commented 3 years ago

Yes please!

brandonpollack23 commented 2 years ago

+1

galacticfungus commented 2 years ago

+1

ArtemMikhaylov commented 2 years ago

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

jittyandiyan commented 2 years ago

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

ArtemMikhaylov commented 2 years ago

@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.

fcat97 commented 1 year ago

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

JavierSegoviaCordoba commented 1 year ago

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

greenrobot-team commented 1 year ago

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

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

sebastianharder commented 1 year ago

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.

NobilityDeviant commented 9 months ago

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.

greenrobot-team commented 9 months ago

@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.

NobilityDeviant commented 9 months ago

@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.

devjn commented 6 months ago

Since Android team is now officially supporting Kotlin Multiplatform for shared business logic, is there going to be any progress towards kotlin multiplatform for ObjectBox?