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

Miguel Fermin

09/23/2019, 9:34 PM
Hi all - The following check always fails for me, causing the
iostarget
to be set to
iosX64
.
Copy code
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64
a

Artyom Degtyarev [JB]

09/24/2019, 11:05 AM
Hello! Please provide some details on the use-case. It should work correctly when you produce framework during the Xcode build process.
m

Miguel Fermin

09/24/2019, 11:32 AM
Hi there - sure, I followed this tutorial (https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/01_Introduction), and everything works good when I build on the simulator, but not on an actual device. After some digging I found that the iOSTarget variable fails at getting the
SDK_NAME
from the xcode environment. If I hardcode one or the other (iosArm64 or iosX64) I'm able to build either on the simulator or device. This is the line that fails:
Copy code
System.getenv("SDK_NAME")
And here's the block that sets the target:
Copy code
//select iOS target platform depending on the Xcode environment variables
    val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iOSTarget("ios") {
        binaries {
            framework {
                baseName = "SharedCode"
            }
        }
    }
a

Artyom Degtyarev [JB]

09/24/2019, 12:31 PM
Please make sure that the Xcode sets the variable correctly. What is the value of
System.getenv("SDK_NAME")
?
m

Miguel Fermin

09/24/2019, 1:54 PM
Sorry, I got caught up in meetings... I found the problem. Silly me copied and pasted the Run Script from the tutorial and didn't realize the need for a new line (or &&) after cd'ing to the framework directory before invoking the ./gradlew task. It's all good now. Thanks!
🎉 1
c

corneil

09/25/2019, 5:38 PM
Just having
js()
without
nodejs {}
or
browser {}
will have this effect