Skip to content

Instantly share code, notes, and snippets.

@epool
Last active December 5, 2023 13:11
Show Gist options
  • Save epool/b55f9b8f64427efc5717510e0246c278 to your computer and use it in GitHub Desktop.
Save epool/b55f9b8f64427efc5717510e0246c278 to your computer and use it in GitHub Desktop.
Builds a XcFramework from a shared module in KMM.
//region XcFramework tasks
val xcFrameworkPath = "xcframework/${project.name}.xcframework"
tasks.create<Delete>("deleteXcFramework") { delete = setOf(xcFrameworkPath) }
val buildXcFramework by tasks.registering {
dependsOn("deleteXcFramework")
group = "build"
val mode = "Release"
val frameworks = arrayOf("iosArm64", "iosX64")
.map { kotlin.targets.getByName<KotlinNativeTarget>(it).binaries.getFramework(mode) }
inputs.property("mode", mode)
dependsOn(frameworks.map { it.linkTask })
doLast { buildXcFramework(frameworks) }
}
fun Task.buildXcFramework(frameworks: List<org.jetbrains.kotlin.gradle.plugin.mpp.Framework>) {
val buildArgs: () -> List<String> = {
val arguments = mutableListOf("-create-xcframework")
frameworks.forEach {
arguments += "-framework"
arguments += "${it.outputDirectory}/${project.name}.framework"
}
arguments += "-output"
arguments += xcFrameworkPath
arguments
}
exec {
executable = "xcodebuild"
args = buildArgs()
}
}
//endregion
@rzolin
Copy link

rzolin commented Dec 5, 2023

Right, I would love to know how to use the script above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment