2

I have been experiencing a troubling problem lately that has to do with the running of tests on a project which has a cocoapods dependency to a framework which crashed at runtime with error:

Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib Referenced from: MyCocoapodsDependency

There are other stackoverflow topics out there about that particular problem but none of them address root cause (for example here), which is that during the "Copy swift standard libraries" step of the test build, the missing library is not copied over.

It looks like this (this is the build log when I build the tests):

missing dylib

When it should look like this (this is the build log for a test app that uses the exact same dependencies):

enter image description here

OnOneSupport seems to have to do with with a project setting that has to do with "Whole module optimization".

enter image description here

But even if I change to "not onOne" it doesn't make a difference. The dylib is referred to in https://github.com/apple/swift/blob/master/cmake/modules/AddSwift.cmake

I cannot for the life of me figure out why it's omitted from the standard libraries build step for one target and not for another, but its obvious that my tests needs it. Anybody know how I can force the compiler to include SwiftOnoneSupport?

Workaround

Add a build phase to the test target (in the project file) that copies libswiftSwiftOnoneSupport.dylib to Frameworks. The dylib can be found at:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bitcode_strip /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/libswiftSwiftOnoneSupport.dylib

enter image description here

Max Boulat
  • 115
  • 7
  • Take a look at my answer here https://stackoverflow.com/a/54034898/191744 adding inherit! :search_paths and changing embedded swift libs in post_install worked for me – zvjerka24 Jan 04 '19 at 08:52

1 Answers1

2

I also had this same issue with two of my frameworks. The strangest thing was that everything was working fine with one of them but not with the other.

While I wasn't able to figure out why this happens (since it seems to be an Xcode bug), I was able to find a pretty neat workaround.

Turns out that using print() anywhere in your code will somehow force libswiftSwiftOnoneSupport.dylib to be loaded. So, by adding something like this the problem should go away:

private func dummy() { 
    print("Hello world!") 
}

I'm using Xcode 10.1, Swift 4.2 and the pod that was giving me this issue was Nimble.

Hope this helps!

LuisCien
  • 6,362
  • 4
  • 34
  • 42