Hello folks, I am following <https://kotlinlang.or...
# multiplatform
d
Hello folks, I am following https://kotlinlang.org/docs/mobile/create-first-app.html tutorial and am wondering if there is a way to add tvOS target as well. I am an iOS/tvOS developer with limited understanding for gradle build system so please bear with me. Also if this is not the right channel please point me to the right one, thanks.
t
Should just be able to add a tvOS target to the generated xcodeproj. The framework file generated from the kotlin portion of things should "just work" with tvOS too, as long as you're not trying to do UI work in Kotlin.
That said, Im not sure how you'd go about handling the integration directly into Android Studio for the tvOS case.
d
I am having issues building the shared framework for tvOS
I am not doing UI work with Kotlin. I did add tvOS target to the Xcode project and added following task in build.gradle for shared code for tvOS
Copy code
val packForXcodeTV by tasks.creating(Sync::class) {
    group = "build"

    //selecting the right configuration for the iOS framework depending on the Xcode environment variables
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>("tvos").binaries.getFramework(mode)

    inputs.property("mode", mode)
    dependsOn(framework.linkTask)

    val targetDir = File(buildDir, "xcode-frameworks-tv")
    from({ framework.outputDirectory })
    into(targetDir)

    doLast {
        val gradlew = File(targetDir, "gradlew")
        gradlew.writeText("#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n")
        gradlew.setExecutable(true)
    }
}
When I run that task as part of
run script
from Xcode I get following error
KotlinTarget with name 'tvos' not found.
t
If you have a look at the default packForXcode it's got this line:
Copy code
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
Based on the docs here (https://kotlinlang.org/docs/reference/mpp-dsl-reference.html) it looks like you just need to follow a similar pattern as the iOS block, swapping out for tvos so you build either
tvosArm64
or
tvosX64
d
thanks, I tried it and now getting
KotlinTarget with name 'tvosX64' not found.
error for simulator
t
And you added a tvos step in the kotlin section of the gradle file that's similar to
Copy code
ios {
    binaries {
        framework {
            baseName = "shared"
        }
    }
}
?
That's all the ideas I've got unfortunately.
d
adding tvos step in kotlin section fixed the error. Thank you
t
Awesome! Always nice when the "I got one more idea" idea actually works