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

Mgj

07/03/2020, 8:06 AM
It seems like you cannot use kotlinx.coroutines.flow.MutableStateFlow in common code? Only platform-specific code?
g

gildor

07/03/2020, 8:13 AM
I didn’t check myself, but it should be available there, it’s in common code: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/common/src/flow/StateFlow.kt#L123
m

Mgj

07/03/2020, 8:15 AM
Yeah the rest of the "flow" namespace seems to be available but not the new-ish StateFlow's which i thought was weird. Im unable to import it and get an error while building about it being an unresolved reference
g

gildor

07/03/2020, 8:19 AM
are you sure that you use 1.3.6+ for common code? Maybe just common uses an old version
m

Mgj

07/03/2020, 8:20 AM
I think i am:
Copy code
sourceSets {
	def coroutines_version = "1.3.7"
	commonMain {
            dependencies {
                implementation(kotlin('stdlib-common'))
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
                // ...
            }
        }
Its the same version i use for the android code where it works fine 🤔
Just for future reference, i needed to add
"org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
as a dependency (note
-common
)
g

gildor

07/03/2020, 2:02 PM
Interesting, I thought that it already works with Gradle metadata without separate dependencies Do you use the latest Gradle?
m

Mgj

07/03/2020, 3:30 PM
Could be because of that, im not on the latest Gradle (using 3.6.3 , 4.x should be out now)
g

gildor

07/03/2020, 3:36 PM
3.6.3? Don't think it's Gradle version, looks like Android Gradle Plugin version
e

edenman

07/03/2020, 6:26 PM
i’m definitely using
MutableStateFlow
in my common code fwiw
oh and yeah i have both
coroutines-core
and
coroutines-core-common
specified in my common module deps. my issue was some transitive dep was screwing up the version # iirc
👍 1
g

gildor

07/04/2020, 2:36 AM
Ahh, transitive dependency can break it, just because there are 2 artifacts with different name but same content, had similar issue when kotlin stdlib artifact was renamed from jre to jdk I think the better solution is exclude it on level of Gradle
l

louiscad

07/04/2020, 8:37 AM
@Mgj Reading your
build.gradle
snippet, I'm not seeing the dependency on kotlinx coroutines common for commonMain, you specified the JVM artifact (note: this becomes correct starting Kotlin 1.4-M2 because these artifacts start being Multiplatform publications)
g

gildor

07/04/2020, 9:08 AM
Oh, so Gradle metadata for coroutines works only from 1.4
l

louiscad

07/04/2020, 9:09 AM
Before 1.4, it works with
-native
prefixed artifacts.
g

gildor

07/04/2020, 9:18 AM
Yes, right, it was only for different native platforms. It was quite messy experience to have all those different dependencies for every platform Even for stdlib or ootlin-test
l

louiscad

07/04/2020, 9:20 AM
Actually, it works for non Kotlin/Native targets/platforms as well, but these are gone(replaced) for 1.4-M2
m

Mgj

07/04/2020, 10:01 AM
Interesting.... good to know, thank you
7 Views