I'm trying to distribute a Kotlin MPP library that...
# kotlin-native
j
I'm trying to distribute a Kotlin MPP library that depends on iOS project. I've tried to include it as a framework, but that way it's not included in the distribution. Right now I'm trying to include the iOS project statically, and I can see the static lib in the resulting .klib distribution. But in runtime it fails with the following:
dyld: Library not loaded: @rpath/iOSProject.framework/iOSProject
Here is cinterops:
Copy code
// Path to .def file
defFile("src/iosMain/cinterop/iOSProject.def")

// Directories for header search (an analogue of the -I<path> compiler option)
includeDirs("$projectDir/native/iOSProject/iOSProject.framework/Headers")
Here is def:
Copy code
language = Objective-C
headers = iOSProject.h iOSProject-Swift.h
staticLibraries = libiOSProject.a
libraryPaths = ../iOSProject.framework
Any idea why it happens? Maybe there are alternative ways to include the library?
a
What Kotlin version you’re using here? There was a similar bug in 1.4.0 milestones some time ago: https://youtrack.jetbrains.com/issue/KT-39396
j
Copy code
1.4.10
I've tried the workaround mention there -
Copy code
"-include-binary", "$projectDir/native/libiOSProject.a"
But result is the same
@Artyom Degtyarev [JB] is it possible that the lib is included, but copied to a wrong path here? This line looks suspicious to me
@rpath/iOSProject.framework/iOSProject
because it's specifed in xcode project, but I'm not sure how kotlin compiler would know to include the library at that place
a
It looks like the compiler links against the framework instead of the static library. Is the
.a
file located inside
iOSProject.framework
?
j
Yes, that
.a
file is there. I've tried with the framework instead, and it finally managed to make it work with the "rpath" argument. The drawback is that it's not included in the klib, so I had to copy the framework and linker options to the project that's supposed to depend on it. Is there any way to include the framework in klib so it would link automatically?
a
@James Smith Were you able to import the framework in the project ever without manually pulling it? also how did you copy the framework in your dependent project ?