SPM problems with loading duplicate libs when using modules / frameworks #265
Description
Description
Version info :
Xcode 12.0
Build version 12A8179i
When using SPM to load RK in Xcode 12 Beta 4, for a project with multiple modules that leverage RK, I run into the following issue :
Swift package product 'ReactiveKit' is linked as a static library by 'Services' and 'API'. This will result in duplication of library code.
If I somehow manage to circumvent that message by linking "binaries with library" and only embedding the frameworks at the product level, the application will compile, but will result in crashes at runtime with warning messages when the application starts similar to :
Class _TtC11ReactiveKit15BlockDisposable is implemented in both moduleA and moduleB
Solution
I unfortunately haven't found many resources on this particular issue with SPM. However this git repo seems to highlight the same issue and mentions the following :
IMHO it's an Xcode issue. Because in SPM documentation, it's mentioned that if you don't want to force either
.dynamic
or.static
you can let blank and it will be automatically manager by the SPM consumer (a.k.a Xcode in our case). Xcode should be smart enough to detect that a SPM library is used twice or more and apply the .dynamic itself or something.
So I gave it a shot, forked RK and forced it be loaded dynamically by using .dynamic
in Package.swift
. And it worked great. No more compilation issues and no runtime crash.