https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Mgj

06/30/2020, 9:10 AM
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

gildor

06/30/2020, 9:13 AM
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

Mgj

06/30/2020, 9:15 AM
but kotlin has interop with java no? Or is that just an android thing?
g

gildor

06/30/2020, 9:17 AM
Kotlin JVM has interop with Java
but Kotlin JS or Kotlin/Native doesn’t
m

Mgj

06/30/2020, 9:19 AM
oh.... well thats good to know, thank you. 😞
g

gildor

06/30/2020, 9:20 AM
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

Mgj

06/30/2020, 9:21 AM
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

gildor

06/30/2020, 9:32 AM
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

Mgj

06/30/2020, 9:34 AM
If JS has support for kotlin i would transpile the Java code to kotlin
g

gildor

06/30/2020, 9:34 AM
I would recommend for start read Kotlin Multiplatform documentation to understand how it works: https://kotlinlang.org/docs/reference/multiplatform.html
m

Mgj

06/30/2020, 9:34 AM
I really dont see any reason for it to depend on anything platform specific like jvm
g

gildor

06/30/2020, 9:35 AM
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

Mgj

06/30/2020, 9:36 AM
Same as i would with android or ios targets. Coroutines are supported and usable in the common sourceset
g

gildor

06/30/2020, 9:37 AM
Same as i would with android or ios targets
What do you mean?
m

Mgj

06/30/2020, 9:37 AM
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

gildor

06/30/2020, 9:38 AM
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

Mgj

06/30/2020, 9:38 AM
Of course, require platform specific schedulers
Again, thats very disappointing 😛
g

gildor

06/30/2020, 9:39 AM
and it’s really not the best way, imo
m

Mgj

06/30/2020, 9:39 AM
I should be able to take a Java POCO and use it in the common sourceset of a KMP project
g

gildor

06/30/2020, 9:39 AM
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

Mgj

06/30/2020, 9:40 AM
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

Arkadii Ivanov

06/30/2020, 9:41 AM
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

andylamax

06/30/2020, 9:43 AM
@Mgj you look like you haven't read how KMP works at all
m

Mgj

06/30/2020, 9:43 AM
@Arkadii Ivanov Its definitely not a full replacement but it might be good enough for my use case
g

gildor

06/30/2020, 9:43 AM
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

Mgj

06/30/2020, 9:44 AM
@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

gildor

06/30/2020, 9:45 AM
Kotlin JVM has perfect Java interop
Kotlin JS has not perfect, but good interop with JS
Kotlin Native has good interop with C
a

Arkadii Ivanov

06/30/2020, 9:46 AM
AFAIK ObservableProperty can not be observed from outside. You can't subscribe. You can only specify a callback when you declaring a property
g

gildor

06/30/2020, 9:47 AM
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

Mgj

06/30/2020, 9:47 AM
@Arkadii Ivanov good point
g

gildor

06/30/2020, 9:48 AM
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

Mgj

06/30/2020, 9:48 AM
Nonsense, kotlin is designed to have good interop with java. It even says so in the official docs
a

andylamax

06/30/2020, 9:49 AM
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

Mgj

06/30/2020, 9:49 AM
You are talking about kotlin multiplatform now. Im talking about kotlin the language
a

andylamax

06/30/2020, 9:50 AM
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

Mgj

06/30/2020, 9:52 AM
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

andylamax

06/30/2020, 9:52 AM
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

gildor

06/30/2020, 10:01 AM
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

Mgj

06/30/2020, 10:02 AM
of course
I never asked for that either though
g

gildor

06/30/2020, 10:13 AM
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

Mgj

06/30/2020, 10:43 AM
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

gildor

06/30/2020, 10:53 AM
if the desire and intention is there
To run jvm bytecode on js and native?
m

Mgj

06/30/2020, 10:54 AM
No.
g

gildor

06/30/2020, 10:56 AM
So what?
d

darkmoon_uk

07/01/2020, 1:24 PM
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

Mgj

07/01/2020, 1:30 PM
Thank you 👍
👌 1
g

gildor

07/01/2020, 3:07 PM
I meantioned it in one of my first messages 🙄
☝️ 2
d

darkmoon_uk

07/02/2020, 1:36 PM
...so you did @gildor, missed that 🤦‍♂️
13 Views