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

coolcat

09/28/2020, 5:19 PM
Please could somebody give me an idiot's guide about the difference between exporting my KMP iOS module as a static or dynamic module. Specifically: how you create each kind, and why you'd want to do one rather than the other.
k

Kris Wong

09/28/2020, 5:52 PM
changing it is as simple as setting a boolean flag on the binary within the KMP DSL in your build file.
are you familiar with the difference between static and dynamic linking?
c

coolcat

09/28/2020, 6:04 PM
I've read many articles on the subject, but the words kind of bounce off my eyeballs! Dynamic libs are linked at runtime right, but in reality what difference does that make for me
k

Kris Wong

09/28/2020, 6:07 PM
static linking offers some optimizations, but there are trade offs that come along with that. https://pewpewthespells.com/blog/static_and_dynamic_libraries.html
c

coolcat

09/29/2020, 5:53 AM
Very helpful link indeed, thanks. But I can’t find which boolean flag I need to set in the build gradle; I have been reading the source of several KMP projects on Github and can’t find the specific setting that dictates whether the output is static or dynamic.
a

Artyom Degtyarev [JB]

09/29/2020, 6:36 AM
Hello, @coolcat! Please see this Kotlin Multiplatform Gradle DSL Reference part, you’re asking about
isStatic
parameter if I got this discussion correctly.
c

coolcat

09/29/2020, 6:40 AM
Thanks, that is what I want. I think that using the cocoapods plugin made me unable to configure this.
a

Artyom Degtyarev [JB]

09/29/2020, 6:44 AM
IIRC something like this can be used to adjust this parameter for a cocoapods-generated framework:
Copy code
kotlin {
    targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
        binaries.withType<org.jetbrains.kotlin.gradle.plugin.mpp.Framework> {
            isStatic = false // it is static by default
        }
    }
}
I borrowed this snippet from https://github.com/JetBrains/kotlin-native/issues/3059, there also are some explanations on static/dynamic differences.