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
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:
After that, I added this dylib file to my project as an Optional Library, on the target of my project.
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)
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: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.
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.
I managed to fix this with these:
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
I had the same issue with
Xcode 13.2.1
The
Xcode 13.3
also can lead to rejecting of your new buildAsync/await causes apps not process for AppStore
.Workaround 1
The simpliest workaround is to update to
Xcode 13.3.1
which supportsSwift 5.6
.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
to6.2
or lower;Alamofire
to5.4.4
or lower;GRDB
to5.16.0
or lower;Most of libraries which causing the failure has such issues. So you can search for those issues in
github
with textlibswift_Concurrency.dylib
. Most of them say that it was fixed inXcode 13.3.1
.In case anyone google’d this problem because of
SwiftLint 0.49.1
crashes onmacOS-11
(probably CI), the solution is simple: update to macOS-12 withXcode 13.4
to takeSwift 5.5
to support the new concurrency library.