Why cant you use RxJava with KMP? Im guessing its ...
# multiplatform
m
Why cant you use RxJava with KMP? Im guessing its because of the Schedulers which have no implementation backing for the different target platforms? Seems odd though that i can add it as a dependency, but the namespaces and classes are just not there - an error would be nice
g
Because RxJava is written in Java and compiled to java class files, not only Schedules, but all code of it, so cannot be used outside of JVM
m
but kotlin has interop with java no? Or is that just an android thing?
g
Kotlin JVM has interop with Java
but Kotlin JS or Kotlin/Native doesn’t
m
oh.... well thats good to know, thank you. 😞
g
But what exactly is you goal? RxJava is indeed Java library, but there are Kotlinx.Coroutines or for example Reaktive, which has API closer to Rxjava https://github.com/badoo/Reaktive
m
Mainly Rx observables which im probably gonna try to replace with kotlin ObservableProperty. But still... RxJava is just one thing, there may be many other java libraries i would like to be able to use. Its very limiting that that is apparently not possible
@gildor you know where i can read more about kotlin multiplatform and java interop?
g
there may be many other java libraries
If you going to use multiplatofrm you need platform libraries, so it should be pure-kotlin lib, or a kotlin lib which wraps platform libraries: https://kotlinlang.org/docs/reference/platform-specific-declarations.html
more about kotlin multiplatform and java interop
There is not java interop in multiplatform How would you run JVM code on JS?
Rx observables which im probably gonna try to replace with kotlin ObservableProperty
Kotlin has coroutines and Flow, which is really good reaplacement for it
m
If JS has support for kotlin i would transpile the Java code to kotlin
g
I would recommend for start read Kotlin Multiplatform documentation to understand how it works: https://kotlinlang.org/docs/reference/multiplatform.html
m
I really dont see any reason for it to depend on anything platform specific like jvm
g
How you can transpile multi-threading language to JS
it’s not about code transpiling
there may be many other java libraries i would like to be able to use
You have to get some Kotlin library, or use platform specific libraries, there is no magic which allows Kotlin use JVM dependencies on JS or vice versa
and there is no transpiling of Java to Kotlin, or Kotlin to Java
m
Same as i would with android or ios targets. Coroutines are supported and usable in the common sourceset
g
Same as i would with android or ios targets
What do you mean?
m
Fine if you dont have full compatibility with Java but many many things are trivially translated to kotlin as per https://kotlinlang.org/docs/reference/java-interop.html
g
yes, Coroutines are supported, but it’s Kotlin language feature + kotlinx.coroutines which is Kotlin library with special support of different platforms, they even don’t have the same feature set (for example JS is single-threaded, so threading is not available)
Again, there is no such thing as transpiling of Java to Kotlin
m
Of course, require platform specific schedulers
Again, thats very disappointing 😛
g
and it’s really not the best way, imo
m
I should be able to take a Java POCO and use it in the common sourceset of a KMP project
g
Not only schedulers, also no volatile, no concurrency, to locks etc
and even bigger problem: no Java runtime, so no JVM collections, no strings etc
m
Sure. You could do what android does and just have limited or no support for certain namespaces and throw an error if you try to use an unsupported namespace
a
Also please read about Kotlin Native memory model, jus to avoid surprises in future.
👍 1
And I think ObservableProperty is not a replacement for RxJava Observable. Closest things are Observable from Reaktive and Flow from kotlinx.coroutines
a
@Mgj you look like you haven't read how KMP works at all
m
@Arkadii Ivanov Its definitely not a full replacement but it might be good enough for my use case
g
Sure. You could do what android does and just have limited or no support for certain namespaces and throw an error if you try to use an unsupported namespace
Which is exactly what KMP does, it allows to write thin wrapper on top of platform-specific APIs, without any non-existing impossible tranpilation magic
m
@andylamax Thank you for the insightful and productive comment. You have any other questions?
🚫 2
@gildor You can do much java interop. Its not magic. Its not impossible. Having no java interop at all seems extreme
g
Kotlin JVM has perfect Java interop
Kotlin JS has not perfect, but good interop with JS
Kotlin Native has good interop with C
a
AFAIK ObservableProperty can not be observed from outside. You can't subscribe. You can only specify a callback when you declaring a property
g
and multiplatofrm is an approach to use Kotlin as universall language to interop with all those platforms, it’s not a way to run Java code on JS
m
@Arkadii Ivanov good point
g
Its not impossible
It’s not impossible, but all attempts to run JVM bytecode on anything except JVM are not really successful And it anyway never was a goal or some promise from Kotlin
m
Nonsense, kotlin is designed to have good interop with java. It even says so in the official docs
a
Kotlin has three flavours. Kotlin/JVM is the one that has good interop with java
Other flavors, don't. There is not interop between Kotlin/JS and Java/Groovy/Scala
m
You are talking about kotlin multiplatform now. Im talking about kotlin the language
a
The Kotlin language is the one with three flavours. Kotlin Multiplatform is being able to share code between different flavours of the Kotlin Language
m
Languages dont have any notion of platforms.... But we're going nowhere now. Thanks for pointing out the kotlin/java interop issue with KMP
a
KMP targerts android,ios,androidNative32 and androidNative64, macos, browser,nodejs, but all of those use one of the three available flavours of the kotlin language. 1. Kotlin/JVM (The famous one) 2. Kotlin/JS 3. Kotlin/Native
g
kotlin/java interop issue with KMP
There is no interop issue with multiplatform, it does exactly what it designed, multiplatform doesn’t have any platform, so it cannot use any platform specific code
m
of course
I never asked for that either though
g
kotlin is designed to have good interop with java. It even says so in the official docs
@Mgj could you please point out on this part of the doc, I curious, maybe it’s really confusing, because of course originally Kotlin target only JVM, maybe it makes sense to make doc more clear UPD: Okay, I see, in Java Interop section, it indeed makes sense to update and mention that it possible only on JVM
m
It is possible to do otherwise as well, if the desire and intention is there
But yeah, it would require some work to be done by the kotlin team
g
if the desire and intention is there
To run jvm bytecode on js and native?
m
No.
g
So what?
d
Spicy thread... @Mgj there's a Kotlin multiplatform port of RxJava called Reaktive: https://badootech.badoo.com/reaktive-a-multiplatform-library-for-reactive-kotlin-android-ios-77b6ff25adb1
So if you're wanting to go K/Multiplatform and work with the familiar ReactiveX API, Badoo have you covered.
m
Thank you 👍
👌 1
g
I meantioned it in one of my first messages 🙄
☝️ 2
d
...so you did @gildor, missed that 🤦‍♂️
160 Views