skip to Main Content

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 {...}
    

7

Answers


  1. Chosen as BEST ANSWER

    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)


  2. The new Async/Await standard for Swift concurrency will only be available on IOS 15 iirc.
    This said, I encountered the same exact error when trying to build for IOS 15, so maybe this will be of use:
    I realized the dyld specified was not in my /usr/lib/swift directory, and that XCode actually could not find it because it was not there. Headed to this site to download Swift 5.5 and installed the PKG on my machine. Normally, you’d be able to select this new version of Swift as a Toolchain in XCode, but this caused my Pods to fail building. So instead, I navigated to /library/developer/toolchains/<snapshotname>/usr/lib/swift/iphoneos/libswift_Concurrency.dylib and added this file as a Embedded Library in my target, as shown here:
    enter image description here

    Every single aspect of this is hacky and a short term solution that you should not ship in any actual product and only use as a placeholder until it is included in the standard Swift library. This said, it actually allowed me to start developing with these features.
    As an aside, I’m currently unable to run my simulator due to unrelated incompatibilities with my Pods and M1 mac, so I’ve only tested this method on physical devices.
    I’m hoping others that encounter this error will find this, but I suspect in your case the file can’t be found simply because the features are not supported on older versions of IOS.

    Login or Signup to reply.
  3. I found this link that works for me. Under [TARGET] > Build Phases > Link Binary With Libraries and add libswift_concurrency.tbd with the optional status.

    Login or Signup to reply.
  4. I managed to fix this with these:

    1. Installed the latest Swift package from apple: https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2021-12-06-a/swift-DEVELOPMENT-SNAPSHOT-2021-12-06-a-osx.pkg
    2. Installed the latest Swift Debugging symbols: https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2021-12-06-a/swift-DEVELOPMENT-SNAPSHOT-2021-12-06-a-osx-symbols.pkg
    3. Unchecked the "Make this app available" Apple Silicon Mac Availability in Pricing and Availability from AppStore
    4. Added the libswift_Concurrency.tbd in Link Binary with Libraries from XCode Build Phases and set as optional
    Login or Signup to reply.
  5. I a similar issue where only TestFlight installed apps would crash on launch with that error (simulator running fine) and it was fixed by updating Xcode to 13.2.1.

    From https://developer.apple.com/documentation/xcode-release-notes/xcode-13_2_1-release-notes

    Resolved Issues

    Fixed an issue where apps built with Xcode 13 or Xcode 13.1 sometimes crashed at launch with an error reporting that the libswift_Concurrency.dylib library was not loaded. This only affected apps that used Swift Concurrency features (such as async/await), deployed to iOS prior to 15, tvOS prior to 15, or watchOS prior to 8, and had bitcode enabled. (86349088)

    Login or Signup to reply.
  6. I had the same issue with Xcode 13.2.1

    The Xcode 13.3 also can lead to rejecting of your new build Async/await causes apps not process for AppStore.


    Workaround 1

    The simpliest workaround is to update to Xcode 13.3.1 which supports Swift 5.6.

    Xcode 13.3 Beta Release Notes:

    Resolved Issues Apps that use back-deployed Swift Concurrency on
    operating systems prior to macOS 10.15, iOS 13, tvOS 13, or watchOS 6
    no longer crash on launch. (87789769)

    Xcode 13.3.1 Release Notes:

    Resolved Issues

    Fixed: Exporting an app that uses Swift’s concurrency features from an
    archive with bitcode might fail when the app targets iOS 13.0–14.7,
    watchOS 6.0–7.6, or tvOS 13.0–14.7. (89271047) When you target iOS
    13.4 and later and enable bitcode, the bitcode segment is now stripped correctly. This fixes a crash that prevented some apps from running in
    older operating systems (iOS 14 and earlier). (90024354) (FB9951126)

    Some of links of this issue Alamofire GRDB.swift RxSwift


    Workaround 2

    There are a lot of libraries which can cause this failure.
    So if you don’t want to update Xcode so just downgrade some of your libraries. For example:

    • RxSwift to 6.2 or lower;
    • Alamofire to 5.4.4 or lower;
    • GRDB to 5.16.0 or lower;
    • etc.

    Most of libraries which causing the failure has such issues. So you can search for those issues in github with text libswift_Concurrency.dylib. Most of them say that it was fixed in Xcode 13.3.1.

    Login or Signup to reply.
  7. In case anyone google’d this problem because of SwiftLint 0.49.1 crashes on macOS-11 (probably CI), the solution is simple: update to macOS-12 with Xcode 13.4 to take Swift 5.5 to support the new concurrency library.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search