Search code examples
iosswiftxcodexcode13

Crash on dyld: Library not loaded: /usr/lib/swift/libswift_Concurrency.dylib running on simulator


I'm implementing a very basic task (download few files from a remote server) on an existing app, to exercise the new Swift Concurrency APIs. The task is done flawlessly on iOS 15: I use a TaskGroup and I receive the images as expected. As this app already exists, I used the @available tag to check if the device can perform my task (if iOS 15, do it. Otherwise, show an alert to the user and do nothing) The problem happens when I try to run this app on a simulator with iOS 13.5, my app crash upon the start with the following error:

dyld: Library not loaded: /usr/lib/swift/libswift_Concurrency.dylib
  Referenced from: /Users/username/Library/Developer/CoreSimulator/Devices/B316A0F0-B7EF-4F5E-8A26-F7FF54E8A681/data/Containers/Bundle/Application/6CF3D46E-3F15-4FA3-BD61-9D353541B9DA/MyApp.app/MyApp
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_SHARED_CACHE_DIR=/Users/username/Library/Developer/CoreSimulator/Caches/dyld/20F71/com.apple.CoreSimulator.SimRuntime.iOS-13-5.17F61
DYLD_ROOT_PATH=/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.5.simruntime/Contents/Resources/RuntimeRoot
DYLD_LIBRARY_PATH=/Users/username/Library/Developer/Xcode/DerivedData/MyApp-bawyiebpygwuwxawcoistefwxuyy/Build/Products/Debug-iphonesimulator:/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.5.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.5.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.5.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib:/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.5.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDI

Environment: Xcode 13.0 beta 2 (13A5155e) Simulator iPhone 8 (iOS 13.5). Swift Language Version 5

Is there something that I can do about it?

Edit: this is how I'm using the if available

@available(iOS 15.0, *)
class SCTestViewController: UIViewController {...}
    

Solution

  • Found a solution based on what @vera-gonzalez did on her case. THIS IS NOT A PRODUCTION CODE. I also downloaded the PKG file from the swift snapshots https://swift.org/download/#snapshots, I got both versions (iphoneos and iphonesimulator) from /Library/Developer/toolchains/<snapshotname>/usr/lib/swift/<version>/libswift_Concurrency.dylib

    After that I created a fat dylib file with lipo:

    ❯ lipo iphoneos/libswift_Concurrency.dylib iphonesimulator/libswift_Concurrency.dylib -create -output libswift_Concurrency.dylib
    ❯ lipo -info libswift_Concurrency.dylib
    Architectures in the fat file: libswift_Concurrency.dylib are: armv7 armv7s i386 x86_64 arm64 arm64e
    

    After that, I added this dylib file to my project as an Optional Library, on the target of my project. image showing the Link Binary With Libraries, showing the Optional on the lib selected

    With that trick I can build, run and archive for both device and simulator on my project for now (the discussion on Swift Forum indicates that this is going to be fixed sometime, but meanwhile, we can test our apps with this)