https://kotlinlang.org logo
#ktor
Title
# ktor
t

tylerwilson

06/14/2021, 3:48 PM
Before wasting time, can I use Ktor in a watchOS app/target?
t

Thomas

06/14/2021, 4:33 PM
Ktor client with iOS engine works for me in a watchOS app
t

tylerwilson

06/14/2021, 4:37 PM
Interesting. May I ask how your gradle is set up? I am using cocoapods integration, which calls the gradle process, passing in the Xcode params. I have something like this:
Copy code
val buildForWatchARM = project.findProperty("kotlin.native.cocoapods.target") == "watchos_arm"
    if (buildForWatchARM) {
        watchosArm32("watchos32")
        watchosArm64("watchos64")

        val watchosMain = sourceSets.maybeCreate("watchosMain")
        sourceSets["watchos64Main"].dependsOn(watchosMain)
        sourceSets["watchos32Main"].dependsOn(watchosMain)

    } else {
        watchosX64("watchos") // simulator
    }
and then a section like so:
Copy code
val watchosMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-ios:$ktorVersion")
            }
        }
but when I try to build the framework within AS, I get errors like so:
Copy code
Could not resolve io.ktor:ktor-client-core:1.6.0.
...
No matching variant of io.ktor:ktor-client-core:1.6.0 was found.
Or are you perhaps linking directly to the generated iOS framework from the watchOS extension?
t

Thomas

06/14/2021, 4:50 PM
Maybe the new
watchosX64
target is not supported yet in Ktor
I am using
watchosX86
for simulator
t

tylerwilson

06/14/2021, 4:50 PM
Good point. I am trying simulator first.
sweet. that got me much further.
do you have a specific watchosMain target set up, or do you re-use the iosMain target?
t

Thomas

06/14/2021, 4:54 PM
I have all Ktor code in an appleMain source set which is shared between ios and watchos
And common / jvm source sets of course
t

tylerwilson

06/14/2021, 4:55 PM
good idea. will look into how to share them. thanks for the help!
t

tylerwilson

06/14/2021, 8:15 PM
Great! Upvoted.
Now can you throw in a PR for maccatalyst? 😉
t

Thomas

06/15/2021, 12:33 AM
Haha unfortunately that's not as easy as this PR
On the roadmap Mac Catalyst was postponed for later so I am afraid we are not going to see support anytime soon
For my project I am considering using Compose UI instead which is JVM (so not Kotlin/Native)
#compose-desktop
t

tylerwilson

06/15/2021, 2:23 AM
That does look pretty cool. Have to get into it. I might look into doing a macOS SwiftUI version of our app, then at least I can use the shared code compiled as a pure macOS framework.
@Thomas Well done on the PR. Approved and Merged! Anxious to get Ktor 1.6.1 now. 🙂
3 Views