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

Devendra Patel

12/03/2020, 5:27 PM
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

Thomas Myrden

12/03/2020, 5:29 PM
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

Devendra Patel

12/03/2020, 5:39 PM
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

Thomas Myrden

12/03/2020, 5:49 PM
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

Devendra Patel

12/03/2020, 6:46 PM
thanks, I tried it and now getting
KotlinTarget with name 'tvosX64' not found.
error for simulator
t

Thomas Myrden

12/03/2020, 6:49 PM
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

Devendra Patel

12/03/2020, 7:04 PM
adding tvos step in kotlin section fixed the error. Thank you
t

Thomas Myrden

12/03/2020, 7:05 PM
Awesome! Always nice when the "I got one more idea" idea actually works
3 Views