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

Marc Reichelt

10/28/2019, 1:40 PM
Does anyone have an issue finding the iosMain source set? I added the following code to my `build.gradle.kts`:
Copy code
sourceSets["iosMain"].dependencies {
        implementation("io.ktor:ktor-client-ios:$ktorVersion")
    }
But Gradle complains with “KotlinSourceSet with name ‘iosMain’ not found.“…
a

Artyom Degtyarev [JB]

10/28/2019, 1:44 PM
Please make sure that you have a target with name “ios”. Default source sets name depends on the target name, as described here(https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#default-project-layout)
m

Marc Reichelt

10/28/2019, 1:59 PM
Ohhhh
By introducing my code to generate a fat framework I changed the architecture name to
iosArm64
, and therefore the target name! Does this mean I’ll now have to add the dependencies to both the
iosArm64
as well as the
iosX64
targets?
s

Sam

10/28/2019, 2:05 PM
You could filter the list of sourceSets by ones starting with "ios" and then calling .dependencies on each one.
👍 1
m

Marc Reichelt

10/28/2019, 2:05 PM
Nice, it works now! Thank you so much @Artyom Degtyarev [JB] 🎉
@Sam yep, that does make sense as well. And the Kotlin DSL makes this damn nice to read!
👍 1
Now I just need to figure out how to define that those 2 targets actually have the same source set
iosMain
, otherwise I would have to have 2 source directories
iosX64Main
and
iosArm64Main
with the same content…
a

Artyom Degtyarev [JB]

10/28/2019, 2:22 PM
m

Marc Reichelt

10/28/2019, 2:32 PM
Thanks, that looks useful. I will dig my head around this, but this is definitely something where we will loose many new developers jumping on KMP - because it’s just pretty complex, and usually people would like to concentrate on the business stuff, and not on figuring out how to resolve all those Gradle configuration stuff…
Oh, wow, there are so many things that are new in the native/multiplatform world. Like the fact that there is no
runBlocking
for coroutines on iOS, so now I have to figure out how to do this myself. If the method is called on a non-UI-thread, how can I simply make ktor client make a HTTP request on the thread it’s currently called?
s

Sam

10/28/2019, 3:00 PM
Ktor calls have to be done on the main thread currently. It has some
object
types that are initialized there on startup. If a call is made on a background thread it will access those objects and cause an illegal state exception.
m

Marc Reichelt

10/28/2019, 4:11 PM
awww, damn
that’s pretty much a dealbreaker 😕
s

Sam

10/28/2019, 7:51 PM
The call doesn't block and on iOS it is using NSURLSession which actually makes the call on a background thread. You would want to avoid doing any heavy workloads with the result on the main thread. For that you could use workers.
r

russhwolf

10/29/2019, 12:54 AM
There is runBlocking for iOS, It’s just missing from JS so it’s not in the common stdlib. But you can define your own expect/actual alias if you just care about JVM and Native.
👍 1
m

Marc Reichelt

10/29/2019, 9:58 AM
Wow, that’s pretty cool - defining an
expect
runBlocking method with the same syntax as the real ones works!
123 Views