Does anyone have an issue finding the iosMain sour...
# multiplatform
m
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
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
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
You could filter the list of sourceSets by ones starting with "ios" and then calling .dependencies on each one.
👍 1
m
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
m
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
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
awww, damn
that’s pretty much a dealbreaker 😕
s
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
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
Wow, that’s pretty cool - defining an
expect
runBlocking method with the same syntax as the real ones works!
216 Views