https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

ribesg

02/26/2019, 11:13 AM
We have a MPP library (Project A) which has a dependency on a Swift Framework (Bugsnag-cocoa) on the iOS side, setup with cinterops, published to a maven repo as a KLibrary. We’re trying to use it in an iOS app setup with a MPP project (Project B) whose goal is to create a Framework with all MPP dependencies for the XCode project. We get the following error when building the Framework (Project B):
Copy code
> Task :linkReleaseFrameworkIos
ld: framework not found Bugsnag
Does that mean that the KLib was not built correctly or that the App project misses something? There is a cinterops-bugsnag.klib in the maven repo for the KLib, maybe it’s not imported correctly?
l

louiscad

02/26/2019, 11:40 AM
r

ribesg

02/26/2019, 11:45 AM
Thanks for that, I’ll have a look. Really looks like what we need!
@louiscad do you know how that is supposed to work with native cinterops dependencies, i.e. not subprojects nor gradle dependencies?
l

louiscad

02/26/2019, 2:16 PM
@ribesg I have no idea. The bottom of that same page talks about cinterop, but if you still encounter a problem or struggle, I think you would be better off asking your specific question back in that channel, or in #kotlin-native
s

svyatoslav.scherbina

02/27/2019, 7:28 AM
You might have passed wrong linker options. Have you specified proper
-F
linker option in your Gradle build script or
.def
file?
r

ribesg

02/27/2019, 9:05 AM
@svyatoslav.scherbina We have it in the Project A but don’t know if we need it in project B, isn’t the Swift dependency supposed to be part of the published klibs? Because it looks like it is, we have a
project-version-cinterop-bugsnag.klib
in the maven repo https://gist.github.com/Ribesg/8e84262953c2fd8c9fcfbd1f6e75bea6
(Also note that I have no idea what I’m doing with the
.def
file, it’s a patchwork of stuff I don’t really understand)
s

svyatoslav.scherbina

02/27/2019, 9:45 AM
-Xexport-library
feature is not supposed to be used for interop libraries. Linker options in Gradle are applied to native binaries, so you should add
-F
to projectB instead.
r

ribesg

02/27/2019, 9:48 AM
@svyatoslav.scherbina But what parameter can I pass to
-F
? Do you mean that I need to redo the whole cinterop process for each project having ProjectA as a dependency?
If I do that I get a new, obvious error:
llvm-lto: error: Linking globals named 'ktype:framework.Bugsnag.BugsnagMetaDataDelegateProtocolMeta': symbol multiply defined!
. Of course I’m now trying to package the same thing multiple times if I redo the cinterop again
s

svyatoslav.scherbina

02/27/2019, 9:52 AM
if I redo the cinterop again
Why are you trying to do this? Adding
"-F$carthageBuildDir"
to projectB’s binary linker opts is enough. Please refer to documentation.
r

ribesg

02/27/2019, 9:55 AM
But this $carthageBuildDir doesn’t exist in ProjectB, so I need to import it again, I just don’t need to redo the cinterop. Also please understand that both documentation and available examples are REALLY poor on the subject of inheritance, which is normal at this point I guess. Thanks for your help
Ok I managed to make everything work. It’s a very hard problem. I would like to provide an open source example demonstrating how you’re supposed to do such thing but I’m not sure if I’ll have the time someday. I guess if someone has a similar problem in the near future you can maybe point him to me
l

louiscad

02/27/2019, 1:12 PM
@ribesg That open source example with a README explaining the issues you encountered would be interesting to have, I don't have the issue yet, but I may use third party libs in iOS dev in a Kotlin MPP.
i

ivan.savytskyi

02/27/2019, 6:02 PM
I have the exact issue, @ribesg could you please share how did you manage to make it work
I’m trying to do exact the same, use 3rd party ios framework in MPP
r

ribesg

02/28/2019, 8:43 AM
@louiscad @ivan.savytskyi I don’t think I have the time to setup a demo project but I’ll try to make a gist with all the most important parts
👍 1
@louiscad @ivan.savytskyi and here it is: https://gist.github.com/Ribesg/95a172ceb2177d74cf5b15993d40092e I created 2 gists, one showing how I created a lib which has a dependency on an iOS Framework, and one showing how I use such lib in an XCode project, through a local MPP project. They’re both linking to each other.
👍 1
l

louiscad

02/28/2019, 11:15 AM
Thank you!
r

ribesg

02/28/2019, 11:29 AM
@louiscad I see that you forked the gist, probably not to lose it, but make sure to use the original as I’m still experimenting and fixing things. Your fork is already outdated and I’m almost at 10 revisions on the other gist 🙂
l

louiscad

02/28/2019, 11:35 AM
Yep, I'll refork when you tell me you've finished your edits 🙂
r

ribesg

02/28/2019, 11:38 AM
Well at this rate I don’t know if I’ll be ever done. I still don’t understand much about the
.def
file, I need to find the time to experiment by removing some of the lines in there and see if everything continues to work. I guess I’m done for the other file for now. Feel free to ping me if you encounter any problem once you start working with that.
6 Views