Hi All. I got an interesting problem. Hope anyone can help me :slightly_smiling_face: So I got a KM...
g
Hi All. I got an interesting problem. Hope anyone can help me 🙂 So I got a KMM project that depends on a local Objective-C project through
cocoapods
, 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:
Copy code
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`:
Copy code
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"))
    }
}
b
Did you ever find a solution to this?
g
Hey. Uf long time I solved it in the end but dont really remember how. If you want you can check the status of our repository and see if you get some light 😉 https://github.com/input-output-hk/atala-prism-apollo
g
Yeah it might have been. We use this now to achieve the same without cocoapods.
Copy code
import 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
    }
}
b
so you guys have local copies of the 3rd party dependencies in your repo?
g
Well they are not actually 3rd party, this dependencies were made for this project only. So we got access to security features of Apple in KMM.
b
ah
g
Yes it might be a different concept for you.
b
ya our kmp library uses Giphy, Gifu, and Sentry interally so trying to bundle them to make xcode happy
well, the device actually