Gonçalo Frade
07/25/2023, 9:18 PMcocoapods
, and my KMM project then needs to publish a Swift Package (I use io.github.luca992.multiplatform-swiftpackage
).
Everything works fine until I try to use the Swift Package in an Swift project and get a:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$__TtC13TestPodTestClass", referenced from:
objc-class-ref in TestModule(result.o)
ld: symbol(s) not found for architecture x86_64
Here is an example with a similar `build.gradle.kts`:
kotlin {
ios()
macosX64()
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
iosSimulatorArm64()
macosArm64()
}
cocoapods {
this.summary = "Summary"
this.version = rootProject.version.toString()
this.authors = "Test"
this.ios.deploymentTarget = "13.0"
this.osx.deploymentTarget = "12.0"
this.tvos.deploymentTarget = "13.0"
this.watchos.deploymentTarget = "8.0"
framework {
baseName = "TestModule"
isStatic = false
}
pod("TestPod") {
version = "1.0.0"
source = path(project.file("../iOSLibs/TestPod"))
}
}
multiplatformSwiftPackage {
packageName("Test")
swiftToolsVersion("5.3")
targetPlatforms {
iOS { v("13") }
macOS { v("11") }
}
outputDirectory(File(rootDir, "output/test"))
}
}
brandonmcansh
02/10/2024, 9:02 PMGonçalo Frade
02/12/2024, 10:01 AMbrandonmcansh
02/12/2024, 12:52 PMGonçalo Frade
02/12/2024, 2:00 PMimport org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
val libraries = listOf("IOHKSecureRandomGeneration", "IOHKCryptoKit")
val sdks = listOf("iphoneos", "iphonesimulator", "macosx")
libraries.forEach { library ->
sdks.forEach { sdk ->
tasks.create<Exec>("build${library.capitalize()}${sdk.capitalize()}") {
group = "build swift"
if (os.isMacOsX) {
when (sdk) {
"iphoneos", "iphonesimulator" -> {
commandLine(
"xcodebuild",
"-project",
"$library/$library.xcodeproj",
"-target",
"${library}Iphoneos",
"-sdk",
sdk
)
}
"macosx" -> {
commandLine(
"xcodebuild",
"-project",
"$library/$library.xcodeproj",
"-target",
"${library}Macos",
"-sdk",
sdk
)
}
}
} else {
commandLine("echo", "Unsupported platform.")
}
workingDir(projectDir)
inputs.files(
fileTree("$projectDir/$library.xcodeproj") { exclude("**/xcuserdata") },
fileTree("$projectDir/$library/$library")
)
when (sdk) {
"iphoneos" -> {
outputs.files(
fileTree(projectDir.resolve("$library/build/Release-iphoneos/"))
)
}
"iphonesimulator" -> {
outputs.files(
fileTree(projectDir.resolve("$library/build/Release-iphonesimulator/"))
)
}
"macosx" -> {
outputs.files(
fileTree(projectDir.resolve("$library/build/Release"))
)
}
}
}
}
}
val deleteBuildFolder by tasks.register<Delete>("deleteBuildFolder") {
group = "build"
delete("$projectDir/build")
libraries.forEach {
delete("$projectDir/$it/build")
}
}
afterEvaluate {
tasks.named("clean") {
dependsOn(deleteBuildFolder)
}
tasks.withType<PublishToMavenRepository>().configureEach {
enabled = false
}
tasks.withType<PublishToMavenLocal>().configureEach {
enabled = false
}
}
brandonmcansh
02/12/2024, 2:33 PMGonçalo Frade
02/12/2024, 2:35 PMbrandonmcansh
02/12/2024, 2:36 PMGonçalo Frade
02/12/2024, 2:36 PMbrandonmcansh
02/12/2024, 2:37 PMbrandonmcansh
02/12/2024, 2:38 PM