https://kotlinlang.org logo
#juul-libraries
Title
# juul-libraries
f

Francis Mariano

07/14/2021, 4:02 PM
Hello folks. In the 0.7.0 kable release the dependency on
native-mt
version of Coroutines was removed. The version of Coroutines in the 0.7.0 kable is 1.5.0 The readme explains about configuration and I get a bit confusing in some points: • Can the version of coroutine on androidMain be greater than kable coroutine version? • Can version of coroutine (native-mt) on nativeMain be greater than kable coroutine version? • Can the line 10 be removed?
Copy code
sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("com.juul.kable:core:0.7.0")  // here the version of Coroutine is 1.5.0
            }
        }

        val androidMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1") // here the version of Coroutine is greater // line 10
            }
        }

        val nativeMain by creating {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1-native-mt") {
                    version {
                        strictly("1.5.1-native-mt")
                    }
                }
            }
        }
    }
}
t

travis

07/14/2021, 4:51 PM
The versions of Coroutines library with and without
-native-mt
do not need to match. So, it is valid to use Coroutines 1.5.1 and 1.5.0 for iOS.
Using the same version would work as well.
The readme is also outdated, there is a PR up that updates it, and may be more understandable? https://github.com/JuulLabs/kable/tree/twyatt/readme-gradle#multiplatform
f

Francis Mariano

07/14/2021, 5:07 PM
I think so. Why did you remove androidMain sourceSets?
t

travis

07/14/2021, 5:15 PM
That was a mistake. I'll fix that now. Thanks for catching it!
Sorry, looking at it more, having Coroutines in
androidMain
is optional, as it is defined in
commonMain
. (in the updated README in the PR linked above)
f

Francis Mariano

07/14/2021, 5:27 PM
Ok Travis. I think that understood now. Coroutines could be optional in nativeMain too
IF
-native-mt is not required, right?
t

travis

07/14/2021, 5:30 PM
Kable needs
-native-mt
on Native, so if you use Kable on your project on a Native target (e.g. iOS) then you'll need
kotlinx-coroutines-core:$version-native-mt
, but if you aren't using Kable for your Native target, then you don't need a specific version of Coroutines for that target.
So, the whole dependency dance is because Kable needs to use the special version (
-native-mt
) of Coroutines, but only for Native targets.
This will be simplified once JetBrains releases their new memory model for Native and combines the
-native-mt
implementation of Coroutines with the mainline Coroutines.
f

Francis Mariano

07/14/2021, 5:34 PM
Very nice Travis. Thank you very much.
t

travis

07/14/2021, 5:39 PM
As an example for your original question re: if the Android dependency on Coroutines (line 10) can be removed, the answer is yes, it is optional, as shown here: https://github.com/JuulLabs/sensortag/blob/main/app/build.gradle.kts The
commonMain
dependency on Coroutines provides the needed Coroutines for the Android target.
You can optionally add a dependency in
androidMain
for
kotlinx-coroutines-android
, which adds additional Android Coroutines features.
f

Francis Mariano

07/14/2021, 5:41 PM
Travis,
Copy code
val commonMain by getting {
    dependencies {
             api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}")
             implementation("com.juul.kable:core:${kableVersion}")
         }
     }
coroutinesVersion
cannot be grater than version of Coroutine in kable
t

travis

07/14/2021, 5:42 PM
It should be fine to have a Coroutines version greater than the one used by Kable.
For example, Kable uses Coroutines 1.5.0, but you can use 1.5.1 and it should work fine.
As long as
-native-mt
is used for Native targets, the Coroutines version can be higher than Kable uses.
f

Francis Mariano

07/14/2021, 5:47 PM
Copy code
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
implementation("com.juul.kable:core:0.7.0")
That not work here. Must be another problem so. I will check here. Thank you very much again
t

travis

07/14/2021, 5:48 PM
What is the failure you're hitting?
f

Francis Mariano

07/14/2021, 5:54 PM
Copy code
val commonMain by getting {
            dependencies {
//                api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
                implementation("com.juul.kable:core:0.7.0")
            }
        }

        val iosMain by getting {
            dependencies {
                api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1-native-mt") {
                    version {
                        strictly("1.5.1-native-mt")
                    }
                }
            }
        }
That works fine, but
Copy code
val commonMain by getting {
            dependencies {
                api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
                implementation("com.juul.kable:core:0.7.0")
            }
        }

        val iosMain by getting {
            dependencies {
                api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1-native-mt") {
                    version {
                        strictly("1.5.1-native-mt")
                    }
                }
            }
        }
Fails the sync gradle
Copy code
Could not resolve org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1.
Required by:
    project :shared
Copy code
Could not resolve org.jetbrains.kotlinx:kotlinx-coroutines-core:{strictly 1.5.1-native-mt}.
Required by:
    project :shared
Copy code
Could not resolve org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0.
Required by:
    project :shared > com.juul.kable:core:0.7.0 > com.juul.kable:core-iosarm64:0.7.0
t

travis

07/14/2021, 5:58 PM
Let me test this in the SensorTag sample real quick.
Oh, your source sets that depend on
iosMain
needs to specify the Coroutines artifact for iOS (e.g.
kotlinx-coroutines-core-iosx64
).
I assume you have other source sets that
dependsOn(iosMain)
?
f

Francis Mariano

07/14/2021, 6:09 PM
No I don´t have other sources. So, I replace
iosMain
by
iosX64Main
and
iosArm64Main
. Works fine now.
👍 1
t

travis

07/14/2021, 6:10 PM
Perfect.
Thanks for the feedback on the
README
, I've updated it to hopefully make it more clear.
👍 1
13 Views