Hey, can someone help me add a dependency on an ob...
# ios
s
Hey, can someone help me add a dependency on an objective-c framework (https://github.com/warrenm/GLTFKit2) in my kotlin multiplatform library? What I did so far is ran the
make-xcframework.sh
script (from the repo I linked), which generated the following dirs: GLTFKit2/archives/iOS/GLTFKit2.xcarchive/Products/Library/Frameworks/GLTFKit2.framework GLTFKit2/archives/iOS_Simulator/GLTFKit2.xcarchive/Products/Library/Frameworks/GLTFKit2.framework Now I am trying to include these frameworks as follows: in GLTFKit.def
Copy code
package = GLTFKit
language = Objective-C
modules = GLTFKit2
in build.gradle.kts
Copy code
fun KotlinNativeTarget.configure(depName: String) {
    val myFrameworkDefFilePath = "src/nativeInterop/cinterop/GLTFKit.def"
    val myFrameworkCompilerLinkerOpts = listOf("-framework", "GLTFKit2",
        "-F/GLTFKit2/archives/$depName/GLTFKit2.xcarchive/Products/Library/Frameworks"
    )

    compilations.getByName("main") {
        val gltf by cinterops.creating {
            defFile(myFrameworkDefFilePath)
            compilerOpts(myFrameworkCompilerLinkerOpts)
        }
    }
    binaries.all {
        linkerOpts(myFrameworkCompilerLinkerOpts)
    }
}
iosX64().configure("iOS_Simulator")
iosArm64().configure("iOS")
iosSimulatorArm64().configure("iOS_Simulator")
After I try and build the kotlin project, I am getting:
Copy code
> Task :library:iosSimulatorArm64Test
dyld[70559]: Library not loaded: @rpath/GLTFKit2.framework/GLTFKit2
  Referenced from: <4017322B-EF43-3665-AD50-A5707DD2BECC> /IdeaProjects/Test/scarlett-character-builder/library/build/bin/iosSimulatorArm64/debugTest/test.kexe
  Reason: tried: '/IdeaProjects/Test/library/build/bin/iosSimulatorArm64/debugTest/Frameworks/GLTFKit2.framework/GLTFKit2' (no such file), '/IdeaProjects/Test/library/build/bin/iosSimulatorArm64/debugTest/Frameworks/GLTFKit2.framework/GLTFKit2' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21F79/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.5.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/GLTFKit2.framework/GLTFKit2' (no such file)
Child process terminated with signal 6: Abort trap
This confuses me, I don’t understand why it is looking here for the framework:
IdeaProjects/Test/library/build/bin/iosSimulatorArm64/debugTest/Frameworks
f
you’re using wrong path. use something like “$projectDir” to get the current directory
s
@François sorry shoulda clarified but I changed up the path in that log, I made some changes since then, and currently I am getting the cinterop tool to work, I can see the kotlin generated code for my objective-c code but when I try to run an iosTest that uses them, it cannot find the framework, am getting the following:
Copy code
Calculating task graph as no cached configuration is available for tasks: :library:cleanIosSimulatorArm64Test :library:iosSimulatorArm64Test
> Task :library:checkKotlinGradlePluginConfigurationErrors SKIPPED
> Task :library:cleanIosSimulatorArm64Test UP-TO-DATE
> Task :library:iosSimulatorArm64ProcessResources NO-SOURCE
> Task :library:cinteropGLTFKit2IosSimulatorArm64 UP-TO-DATE
> Task :library:compileKotlinIosSimulatorArm64
> Task :library:iosSimulatorArm64MainKlibrary
> Task :library:xcodeVersion
w: Kotlin <-> Xcode compatibility issue:
The selected Xcode version (15.4) is higher than the maximum known to the Kotlin Gradle Plugin.
Stability in such configuration hasn't been tested, please report encountered issues to <https://kotl.in/issue>
Maximum tested Xcode version: 15.3
To suppress this message add 'kotlin.apple.xcodeCompatibility.nowarn=true' to your gradle.properties
> Task :library:compileTestKotlinIosSimulatorArm64
> Task :library:linkDebugTestIosSimulatorArm64 FAILED
e: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
ld: warning: Could not find or use auto-linked framework 'GLTFKit2': framework 'GLTFKit2' not found
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_GLTFAsset", referenced from:
       in test.kexe.o
ld: symbol(s) not found for architecture arm64
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':library:linkDebugTestIosSimulatorArm64'.
> Compilation finished with errors
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.
BUILD FAILED in 10s
I put a minimal reproducible example over here: https://github.com/dosier/kotlin-gltfkit-example
So I figured I should maybe include the framework path in the binaries, like this:
Copy code
binaries.all {
            linkerOpts("-F$path")
        }
But if I do that I am getting:
Copy code
> Task :library:iosSimulatorArm64Test FAILED
dyld[50249]: Library not loaded: @rpath/GLTFKit2.framework/GLTFKit2
  Referenced from: <CA5575AE-DDAD-374C-BEE7-9C8C26A0E87E> /Users/stanvanderbend/IdeaProjects/multiplatform-library-template-main/library/build/bin/iosSimulatorArm64/debugTest/test.kexe
  Reason: tried: '/Users/stanvanderbend/IdeaProjects/multiplatform-library-template-main/library/build/bin/iosSimulatorArm64/debugTest/Frameworks/GLTFKit2.framework/GLTFKit2' (no such file), '/Users/stanvanderbend/IdeaProjects/multiplatform-library-template-main/library/build/bin/iosSimulatorArm64/debugTest/Frameworks/GLTFKit2.framework/GLTFKit2' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21F79/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.5.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/GLTFKit2.framework/GLTFKit2' (no such file)
Child process terminated with signal 6: Abort trap

Execution failed for task ':library:iosSimulatorArm64Test'.
> command '/usr/bin/xcrun' exited with errors (exit code: 134)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.
BUILD FAILED in 6s
6 actionable tasks: 2 executed, 4 up-to-date
Configuration cache entry stored.
I am so confused, I kinda just want that framework to be embedded into the framework generated by the kotlin code, and it seems the target is expected to have it in there judging from the logs, so why is it not there, or do I have to create a custom gradle task to copy it over there during the build process?
Oh my god, I think I just figured it out
I had to pass the -rpath to linkerOpts
Copy code
binaries.all {
    linkerOpts("-F$path", "-rpath", path)
}
Okay it works for the test now, but if I implement this project into another project as a multiplatform lib, I am getting the following again:
Copy code
ld: warning: object file (/private/var/folders/tv/swp8bxz5579bfcq0t8p3jvj80000gn/T/included8954744631975629192/libskunicode_core.a[arm64][2](libskunicode_core.SkUnicode.o)) was built for newer 'iOS-simulator' version (15.0) than being linked (14.0)
ld: warning: Could not find or use auto-linked framework 'GLTFKit2': framework 'GLTFKit2' not found
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_GLTFAsset", referenced from:
       in composeApp.framework.o
ld: symbol(s) not found for architecture arm64
Which I guess including it in the binaries again should fix it but that’s kinda inelegant, I wish it was somehow included in the kotlin native library
m
You would need to link statically to embed the framework into native app. I've managed to do it for simple
.o
files but not for
.framework
Please update if you figure this one out, I would love to know the solution 🙌
also if are publishing your KMP lib to local maven for testing it sometimes helps to change the version of the lib - say
0.0.1 -> 0.0.2
. IDK why - probably some gradle caching issues