Hey guys! I’m generating and publishing a .klib li...
# kotlin-native
s
Hey guys! I’m generating and publishing a .klib library artifacts using kotlin/native for the following ios targets:
Copy code
components.main {
    targets = ['ios_arm64', 'ios_x64']
    outputKinds = [KLIBRARY]
    baseName = "kotlinmultiplatformstorage-ios"

    dependencies {
        cinterop("KeychainWrapper"){
            packageName "com.netguru.keychainWrapper"
            includeDirs {
                allHeaders "./KeychainWrapper.framework/Headers"
            }
            linkerOpts "-F${projectDir}"
        }
    }
}
As the result I have the following artifacts built:
Copy code
* kotlinmultiplatformstorage-common
* kotlinmultiplatformstorage-android
* kotlinmultiplatformstorage-ios
* kotlinmultiplatformstorage-ios_debug_ios_arm64
* kotlinmultiplatformstorage-ios_debug_ios_x64
Next, I’m trying to use in the sample app configured using
kotlin-multiplatform
plugin with the following gradle build script:
Copy code
plugins {
    id 'kotlin-multiplatform' version '1.3.0'
}
kotlin {
    targets {
        final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") ? presets.iosArm64 : presets.iosX64

        fromPreset(presets.android, 'android')
        fromPreset(presets.iosArm64, 'ios') {
            compilations.main.outputKinds('FRAMEWORK')
        }
    }
    
    configurations {
        compileClasspath
    }

    task packForXCode(type: Sync) {
        final File frameworkDir = new File(buildDir, "xcode-frameworks")
        final String mode = System.getenv('CONFIGURATION')?.toUpperCase() ?: 'DEBUG'

        inputs.property "mode", mode
        dependsOn kotlin.targets.ios.compilations.main.linkTaskName("FRAMEWORK", mode)

        from { kotlin.targets.ios.compilations.main.getBinary("FRAMEWORK", mode).parentFile }
        into frameworkDir

        doLast {
            new File(frameworkDir, 'gradlew').with {
                text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
                setExecutable(true)
            }
        }
    }
}
tasks.build.dependsOn packForXCode
When building sampleapp project I’m having the following error thrown:
Copy code
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_Keychain", referenced from:
      objc-class-ref in combined.o
ld: symbol(s) not found for architecture arm64
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
Do you have any idea what can possibly be wrong with this config?
My .def file looks like this:
Copy code
language = Objective-C
headers = Keychain.h KeychainQuery.h KeychainWrapper.h
compilerOpts = -framework KeychainWrapper
s
You're missing a
linkerOpts
line.
👀 1