Search code examples
macoskotlin-multiplatform

Kotlin Multi Platform framwork CodeSig problem on a Mac OS application


I created a module using kotlin multi-platform and is it is working perfectly on Android and iOS, but when I try to do the same for a macOS app I get the following error:

XYZ.app: code object is not signed at all
Command CodeSign failed with a nonzero exit code

I'm generating the framework as follow:

kotlin {
    jvm("android")

    macosX64("mac") {
        binaries {
            framework {
                baseName = "XyzForMac"
            }
        }
    }

    def iosClosure = {
        binaries {
            framework {
                baseName = "XyzForIos"
            }
        }
    }
    if (System.getenv("SDK_NAME")?.startsWith("iphoneos")) {
        iosArm64("ios", iosClosure)
    } else {
        iosX64("ios", iosClosure)
    }

    sourceSets {…}
}

task packForXcode(type: Sync) {
    def targetDir = new File(buildDir, "xcode-frameworks")
    def mode = System.getenv("CONFIGURATION") ?: "DEBUG"

    def frameworkMac = kotlin.targets.getByName("mac").binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn frameworkMac.linkTask
    from frameworkMac.outputDirectory
    into targetDir

    def frameworkIos = kotlin.targets.getByName("ios").binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn frameworkIos.linkTask
    from frameworkIos.outputDirectory
    into targetDir

    doLast {
        def gradlew = new File(targetDir, "gradlew")
        gradlew.text = """\
            |#!/bin/bash
            |export 'JAVA_HOME=${System.getProperty("java.home")}'
            |cd '${rootProject.rootDir}'
            |./gradlew \$@""".stripMargin().stripIndent()
        gradlew.setExecutable(true)
    }
}

tasks.getByName("build").dependsOn(packForXcode)

It looks I'm doing everything correctly, especially because the app is running as expected on Android and iOS. I'm wondering if I missing any mac os specific configuration to make it works…


Solution

  • I solve the problem changing the approach, instead of using the custom task packForXcode and importing manually the framework, I'm using now the CocoaPods integration, so what I did:

    • Using cocoapods, deleting the packForXcode task (and the custom steps on Xcode)
    • I'm moving the targets to a specific block on gradle build:
    • Because I'm using cocoapods there are no different packed binaries anymore
    kotlin {
        targets { // <-- this is new
            jvm("android")
    
            macosX64("mac") {
                binaries {
                    framework("Xyz") // Removed the ForMac
                }
            }
    
            def iosClosure = {
                binaries {
                    framework("Xyz") // Removed the ForIos
                }
            }
            if (System.getenv("SDK_NAME")?.startsWith("iphoneos")) {
                iosArm64("ios", iosClosure)
            } else {
                iosX64("ios", iosClosure)
            }
        }
        cocoapods {…} // cocoa pods block
        sourceSets {…}
    }