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

Derek Ellis

09/02/2020, 9:59 PM
Does the new cocoapods plugin support hierarchical project structures for ios targets? The samples (https://github.com/Kotlin/kotlin-with-cocoapods-sample) declare the iOS target using
ios()
but then use symlinks between the x86 and arm source sets. I can't seem to get any cocoapods imports to work in the shared iOS sourceset.
I should note that this is mainly about code completion. It seems to compile fine
Opened an issue for good measure https://youtrack.jetbrains.com/issue/KT-41631
t

Tijl

09/03/2020, 7:14 AM
it does not, commonizer only supports platform libraries
a very limiting restriction, see details here: https://github.com/JetBrains/kotlin/blob/1.4.0/native/commonizer/README.md hopefully it will change soon or workarounds will be found. The way I deal with it is to set
Copy code
kotlin.mpp.enableGranularSourceSetsMetadata=false
and then still use the
ios()
declaration, combined with
Copy code
val iosX64Main by getting {
    kotlin.srcDir("iosMain")
}
val iosArm64Main by getting {
    kotlin.srcDir("iosMain")
}
This creates a warning when importing about overlapping sourcesets but it does not seem to break anything. In some projects by default I only use one of the two and pnly enable both when publishing. As you already mention symlinking will also work (but I suspect it will break checkouts on Windows).
👍 1
d

Derek Ellis

09/03/2020, 2:47 PM
I worked around it by sticking to the good ol' environment variable lookup:
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") {}