https://kotlinlang.org logo
#ios
Title
# ios
b

Bastian

10/05/2021, 12:43 PM
Hey there! 👋 I'm trying to pack the classes of a
cinterop multiplatform dependency
into the
shared.framework
for my iOS app (to make them available). The dependency uses
cinterop
as it's wrapping a C library. I'm already trying to
export
it via the Gradle setup (see setup in the thread). Though when building in either Xcode or AppCode, I get an error about
missing symbols for architecture x86_64
and a warning that the
dependency can't be exported
(see error log in the thread). I tried fixing this by including the
.def
file of the wrapping dependency and the
include
folder of the C library itself and making the export
transitive
. But this didn't help. I'm using Kotlin 1.5.31.
1
setup omitted android setup and rest of file for brevity
Copy code
kotlin {
    ios {
        binaries {
            framework {
                baseName = "shared"
                export("io.github.matrixkt:client:$matrixKtVersion")
                export("io.github.matrixkt:olm:$matrixKtVersion")
            }
        }
        compilations.getByName("main") {
            val libolm by cinterops.creating {
                defFile(project.file("libolm.def"))
                includeDirs(projectDir.resolve("include"))
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2")
                implementation("io.ktor:ktor-client-core:$ktorVersion")
                api("io.github.matrixkt:client:$matrixKtVersion")
                api("io.github.matrixkt:olm:$matrixKtVersion") {
                    // android target will pick up "aar" version instead (see androidMain)
                    exclude(group="net.java.dev.jna", module="jna")
                }
                implementation("org.matrix.gitlab.matrix-org:olm:3.2.4")
            }
        }

        val iosMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-ios:$ktorVersion")

                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion") {
                    version {
                        strictly(coroutineVersion) // still got to enforce
                    }
                }
            }
        }
    }
}
error when building both in AppCode and Xcode _omitted some "_olm" missing references for brevity_
Copy code
> Task :shared:cinteropLibolmIosX64 UP-TO-DATE
> Task :shared:compileKotlinIosX64 UP-TO-DATE
> Task :shared:linkDebugFrameworkIosX64
w: Interop library /Users/bc/.gradle/caches/modules-2/files-2.1/io.github.matrixkt/olm-iosx64/0.1.5/7175481a6a0031fc9611b550bbcf7658d69c6d4f/olm-cinterop-libolm can't be exported with -Xexport-library
e: /Applications/Xcode-12.5.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors

The /Applications/Xcode-12.5.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
Undefined symbols for architecture x86_64:
  "_olm_sas_set_their_key", referenced from:
      _colm_internal_olm_sas_set_their_key_wrapper130 in result.o

...

  "_olm_outbound_group_session_message_index", referenced from:
      _colm_internal_olm_outbound_group_session_message_index_wrapper30 in result.o
ld: symbol(s) not found for architecture x86_64

> Task :shared:linkDebugFrameworkIosX64 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared:linkDebugFrameworkIosX64'.
> Compilation finished with errors
So I was able to solve it. All I had to do was • make sure the Kotlin Multiplatform dependency had C-Bindings for iOS Architectures • compile the C-dependency of my dependency for iOS myself (as there were no prebuilts) (Found an iOS wrapper project, which luckily had a
Package.swift
defining a target for only the C-dependency) So I could use
xcodebuild
to compile the lib • put the built library into my KM project • link it in my
binaries { framework { ... }}
25 Views