Closed ychescale9 closed 3 years ago
hi! for regular framework at now i suggest next approach: add copy action to Link tasks, so after each compilation of kotlin/native all generated sources will be moved to your directory.
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink>().matching {
it.binary is org.jetbrains.kotlin.gradle.plugin.mpp.Framework
}.configureEach {
doLast {
val swiftDirectory = File(destinationDir, "${binary.baseName}Swift")
val xcodeSwiftDirectory = File(buildDir, "generated/swift")
swiftDirectory.copyRecursively(xcodeSwiftDirectory, overwrite = true)
}
}
and add this directory into xcode project by "add files". see my sample - https://github.com/Alex009/moko-kswift-usage-sample/tree/regular-framework and here commit with integration - https://github.com/Alex009/moko-kswift-usage-sample/commit/fc921315acb4baa06cbb6038bcd77a639cb329b0
Thanks!
@ychescale9 Sample does not compile in Apple M1 mac
Also, when I use this workaround in latest KMM template from Android Studio. destinationDir is not defined, looks like it is removed. I am not able to generate these classes. Can you please help?
Ok this works by replacing destinationDir
with outputFile.get()
Thanks to PR
Full snippet
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink>().matching {
it.binary is org.jetbrains.kotlin.gradle.plugin.mpp.Framework
}.configureEach {
doLast {
val swiftDirectory = File("${outputFile.get()}/..", "${binary.baseName}Swift")
val xcodeSwiftDirectory = File(buildDir, "generated/swift")
swiftDirectory.copyRecursively(xcodeSwiftDirectory, overwrite = true)
}
}
However, Moko classes are not being generated in case of latest XCFramework syntax
kotlinArtifacts {
Native.XCFramework("BL") {
targets(iosArm64)
modes(DEBUG)
// dynamic framework
isStatic = false
// disable bitcode
embedBitcode = EmbedBitcodeMode.DISABLE
}
}
}
👋
I'm using
:embedAndSignAppleFrameworkForXcode
to build a regular framework instead of using Cocoapods.I can see the generated
.swift
sources available inbuild/xcode-framework/$(CONFIGURATION)/$(SDK_NAME)
but I can't reference them from the iOS project. Is there anything manual process that needs to be done here?