Xcode 16.4 iOS 18.5 simulator crashes for Apps requiring webkit

WKWebView based apps crash in today's Xcode 16.4 iOS 18.5 simulator with messages including:

"Library not loaded: /usr/lib/swift/libswiftWebKit.dylib"

and of the form

"/Users/yyy/Library/Developer/Xcode/DerivedData/zzz/Build/Products/Debug-iphonesimulator/libswiftWebKit.dylib' (no such file)"

Answered by Frameworks Engineer in 841589022

This issue is tracked in WebKit's bug tracker: https://bugs.webkit.org/show_bug.cgi?id=293831

Copying two workarounds listed there:

At this time, there are some workarounds that developers can use for testing and debugging in iOS 18.5 simulator:

Option 1: Change your app's deployment target to iOS 18.4 or later.

  1. Set IPHONEOS_DEPLOYMENT_TARGET = 18.4 in build settings, or use Xcode's UI: Select the app's target in a xcodeproj file, then go to General > Minimum Deployments > iOS and set it to 18.4.

  2. Rebuild the app.


Option 2: Set DYLD_FALLBACK_LIBRARY_PATH in the app's run action. This will allow you to test in iOS 18.5 simulator while continuing to deploy to older OS versions.

  1. Find the simulator runtime's path using xcrun simctl list runtimes -v. It will be a path like "/Library/Developer/CoreSimulator/Volumes/iOS_22F77/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.5.simruntime".

  2. Add "Contents/Resources/RuntimeRoot/System/Cryptexes/OS/usr/lib/swift" to this path.

  3. In Xcode, navigate to the launch arguments pane of your app's scheme. (Product > Scheme > Edit Scheme > Run > Arguments). Add a "DYLD_FALLBACK_LIBRARY_PATH" environment variable, whose value is the path you computed. It will be something like this:

DYLD_FALLBACK_LIBRARY_PATH = /Library/Developer/CoreSimulator/Volumes/iOS_22F77/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.5.simruntime/Contents/Resources/RuntimeRoot/System/Cryptexes/OS/usr/lib/swift
  1. Run the app (no need to rebuild).

For what it's worth, WebKit's bug will be marked as resolved when the issue is fixed on WebKit's main branch, not when the fix is available in a new simulator runtime.

I'm facing the same issue. We have one file that "import WebKit" -- no manual linking is in place.

It ran fine on iOS 18.4/Xcode 16.3, but started crashing in Xcode 16.4/iOS 18.5

I'm facing the same issue, not it looks like I can't run the app on any simulator. Works fine if I run on device and from builds coming from Xcode Cloud, would love to know of a workaround so I can keep using the simulator 😭

In my case, importing WebKit and displaying WKWebViews works, but calling some specific APIs like createPDF triggers the exact same issue.

The only fix I found was changing the deployment target to 18.4 or 18.5, in the build settings of a duplicated Xcode configuration I use only to run my app in the simulator.

FB17731385 if anyone at Apple is reading this.

Greg de J. found a solution. Turns out this only happens if you call some of the WKWebView APIs, see: https://mastodon.social/@quicheindustries/114590816761623008

He found out that the issue came from calling WKWebView.createPDF. In my case, I was using WKWebView.createWebArchiveData, which also triggers the issue.

Until it's solved by Apple, the easiest fix is to compile out this code on the simulator using the #if !targetEnvironment(simulator) directive.

Changing my code to this, let's the app run on the simulator without issues:

#if !targetEnvironment(simulator)
    webView.createWebArchiveData { _ in }
#endif

It seems that the problem reaches into #Preview also - since #Preview seems to depend on the same missing libraries. I'm backing out of 16.4 for now, returning to 16.3 with its own set of problems - but at least I can simulate and preview.

Following up - and now back on Xcode 16.3 - including iOS 18.5 in the simulator: This works out really well as I can now #Preview, and simulate(iOS 18.5) without crashes, and build for TestFlight and deployment.

I'll wait awhile before I burn more hours trying to get Xcode 16.4 to behave.

I'm seeing the same crash here. Everything works fine on Xcode 16.3 with the iOS 18.4 Simulator.

We're also experiencing this exact crash. No problems on Xcode 16.3 with the 18.4 runtime.

Same thing here, this is fairly disruptive to our workflow as we have a workaround to set up the simulator project to have a min iOS version of 18.4.

Ditto: worked fine here with iOS 18.4 simulator built by Xcode 16.3.

Accepted Answer

This issue is tracked in WebKit's bug tracker: https://bugs.webkit.org/show_bug.cgi?id=293831

Copying two workarounds listed there:

At this time, there are some workarounds that developers can use for testing and debugging in iOS 18.5 simulator:

Option 1: Change your app's deployment target to iOS 18.4 or later.

  1. Set IPHONEOS_DEPLOYMENT_TARGET = 18.4 in build settings, or use Xcode's UI: Select the app's target in a xcodeproj file, then go to General > Minimum Deployments > iOS and set it to 18.4.

  2. Rebuild the app.


Option 2: Set DYLD_FALLBACK_LIBRARY_PATH in the app's run action. This will allow you to test in iOS 18.5 simulator while continuing to deploy to older OS versions.

  1. Find the simulator runtime's path using xcrun simctl list runtimes -v. It will be a path like "/Library/Developer/CoreSimulator/Volumes/iOS_22F77/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.5.simruntime".

  2. Add "Contents/Resources/RuntimeRoot/System/Cryptexes/OS/usr/lib/swift" to this path.

  3. In Xcode, navigate to the launch arguments pane of your app's scheme. (Product > Scheme > Edit Scheme > Run > Arguments). Add a "DYLD_FALLBACK_LIBRARY_PATH" environment variable, whose value is the path you computed. It will be something like this:

DYLD_FALLBACK_LIBRARY_PATH = /Library/Developer/CoreSimulator/Volumes/iOS_22F77/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.5.simruntime/Contents/Resources/RuntimeRoot/System/Cryptexes/OS/usr/lib/swift
  1. Run the app (no need to rebuild).

For what it's worth, WebKit's bug will be marked as resolved when the issue is fixed on WebKit's main branch, not when the fix is available in a new simulator runtime.

I tested both options separately. Both worked. I really appreciate the rapid response. Sincere thanks.

For me the option 2 is not working (and option 1 is not really an option as we need to support older iOS versions). I followed the instructions, added the DYLD_FALLBACK_LIBRARY_PATH argument to the Run configuration of my scheme like this:

DYLD_FALLBACK_LIBRARY_PATH=/Library/Developer/CoreSimulator/Volumes/iOS_22F77/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.5.simruntime/Contents/Resources/RuntimeRoot/System/Cryptexes/OS/usr/lib/swift

But the app still crashed, and when it logs the dyld config, it prints this:

DYLD_FALLBACK_LIBRARY_PATH=/Library/Developer/CoreSimulator/Volumes/iOS_22F77/Library/Developer/CoreSimulator/Profiles/Runtimes/

So it seems my value for DYLD_FALLBACK_LIBRARY_PATH is just ignored.

I checked it a thousand times and don't understand what I'm doing wrong. Is this working for other people too?

Edit

Found the solution, see comments if you run into the same problem.

Option 2 seems to have a limitation where previews do not work. Is there a way to inject the DYLD_FALLBACK_LIBRARY_PATH into preview contexts?


    FailedToAnalyzeBuiltTargetDescription: Could not analyze the built target description for AppName to create the preview.
    
    buildableName: AppName
    
    ==================================
    
    |  CouldNotFindLibrary: Could not find library with name ”/usr/lib/swift/libswiftWebKit.dylib“

While Option 1 isn't really an option for the vast majority of companies, Option 2 doesn't work with Preview & Xcode Cloud.

As the variation on option 2 suggested here, one can use a Run Script Phase. The cons is that it will be dynamically switch to the run destination runtime (unless run without build is used with a different run destination).

if [ $XCODE_VERSION_ACTUAL -gt 1640 ]; then
    echo >&2 "error: time to remove 'libswiftWebKit' patch"
    exit 1
fi

DYLD_FALLBACK_LIBRARY_PATH=$(xcrun simctl list devices -v | awk -v device_uuid=$TARGET_DEVICE_IDENTIFIER '/^--/ { RUNTIME=$0 } $0 ~ device_uuid { print RUNTIME }' | sed -E 's/.*\[(.*)\].*/\1/')

DYLD_FALLBACK_LIBRARY_PATH="$DYLD_FALLBACK_LIBRARY_PATH/Contents/Resources/RuntimeRoot/System/Cryptexes/OS/usr/lib/swift"

ln -sf "$DYLD_FALLBACK_LIBRARY_PATH/libswiftWebKit.dylib" "$BUILT_PRODUCTS_DIR/libswiftWebKit.dylib"

I can confirm that I'm facing the same issue:

Library not loaded: /usr/lib/swift/libswiftWebKit.dylib

If you set "User Script Sandboxing" to "No" in the Build Settings and register the following script in the "Run Script" phase of Build Phases, the simulator will no longer crash in either Xcode 26 or Xcode 16.4.

if [ "$PLATFORM_DISPLAY_NAME" = "iOS Simulator" ]; then KEYWORD="iOS ${TARGET_DEVICE_OS_VERSION}" DYLD_FALLBACK_FRAMEWORK_PATH=$(xcrun simctl list devices -v | grep "$KEYWORD" | awk -F'[][]' '{print $2}') DYLD_FALLBACK_FRAMEWORK_PATH="${DYLD_FALLBACK_FRAMEWORK_PATH}/Contents/Resources/RuntimeRoot/System/Cryptexes/OS/usr/lib/swift/" LIBRARY_FILE="libswiftWebKit.dylib" ln -sf "${DYLD_FALLBACK_FRAMEWORK_PATH}/${LIBRARY_FILE}" "${BUILT_PRODUCTS_DIR}/${LIBRARY_FILE}" echo "👉Created an alias for ${LIBRARY_FILE}" fi

I have the same issue, and do not have the library there: Mac-Studio:Volumes MGW$ ls /usr/lib/swift libswiftCreateML.dylib libswiftShazamKit.dylib libswiftVirtualization.dylib libswiftIdentityLookup.dylib libswiftSoundAnalysis_Private.dylib playgrounds libswiftRemoteMirror.dylib libswiftSoundAnalysis.dylib

How do install the library? Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: DYLD 1 Library missing Library not loaded: /usr/lib/swift/libswiftWebKit.dylib Referenced from: <0A128AB5-ED39-36A9-8EC3-7231029D42D3> /Users/USER/Library/Developer/CoreSimulator/Devices/CA0B3CCD-BD38-4766-A17E-463632FFDD04/data/Containers/Bundle/Application/915B71DC-BD1F-412F-A5EA-62C2867FAEF1/Runner.app/Frameworks/flutter_inappwebview_ios.framework/flutter_inappwebview_ios Reason: tried: '/Library/Developer/CoreSimulator/Volumes/iOS_22E238/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib' (no such file), '/usr/lib/swift/libswiftWebKit.dylib' (no such file, not in dyld cache), '/Library/Developer/CoreSimulator/Volumes/iOS_22E238/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libswiftWebKit.dylib' (no such file) (terminated at launch; ignore backtrace)

Can I temporarily copy it into place from one of the other locations?

Mac-Studio:Volumes MGW$ cd /Library/Developer/CoreSimulator/Volumes
Mac-Studio:Volumes MGW$ ls
iOS_21A342	iOS_21E213	iOS_22A3351	iOS_22C150	iOS_22G86
iOS_21C62	iOS_21F79	iOS_22B81	iOS_22E238	tvOS_22L572
Mac-Studio:Volumes MGW$ find . -name libswiftWebKit.dylib -print
./iOS_21A342/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib
./iOS_22C150/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.2.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib
find: ./iOS_22C150/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.2.simruntime/Contents/Resources/RuntimeRoot/private/var/db/modelmanagerd: Permission denied
./iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib
./iOS_22G86/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.6.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib
./iOS_22G86/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.6.simruntime/Contents/Resources/RuntimeRoot/System/Cryptexes/OS/usr/lib/swift/libswiftWebKit.dylib
find: ./iOS_22G86/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.6.simruntime/Contents/Resources/RuntimeRoot/private/var/mobile: Permission denied
find: ./iOS_22G86/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.6.simruntime/Contents/Resources/RuntimeRoot/private/var/db/modelmanagerd: Permission denied
./iOS_22E238/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.4.simruntime/Contents/Resources/RuntimeRoot/System/Cryptexes/OS/usr/lib/swift/libswiftWebKit.dylib
find: ./iOS_22E238/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.4.simruntime/Contents/Resources/RuntimeRoot/private/var/mobile: Permission denied
find: ./iOS_22E238/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.4.simruntime/Contents/Resources/RuntimeRoot/private/var/db/modelmanagerd: Permission denied
./iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib
./iOS_21F79/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.5.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib
./tvOS_22L572/Library/Developer/CoreSimulator/Profiles/Runtimes/tvOS 18.5.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib
find: ./tvOS_22L572/Library/Developer/CoreSimulator/Profiles/Runtimes/tvOS 18.5.simruntime/Contents/Resources/RuntimeRoot/private/var/mobile: Permission denied
find: ./tvOS_22L572/Library/Developer/CoreSimulator/Profiles/Runtimes/tvOS 18.5.simruntime/Contents/Resources/RuntimeRoot/private/var/db/modelmanagerd: Permission denied
./iOS_22B81/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.1.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib
find: ./iOS_22B81/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.1.simruntime/Contents/Resources/RuntimeRoot/private/var/db/modelmanagerd: Permission denied
./iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib
find: ./iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.0.simruntime/Contents/Resources/RuntimeRoot/private/var/db/modelmanagerd: Permission denied

NO apparently SIP prevents it:

Mac-Studio:Volumes MGW$ sudo cp -f "/Library/Developer/CoreSimulator/Volumes/iOS_22G86/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.6.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib" "/Library/Developer/CoreSimulator/Volumes/iOS_22E238/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/"
cp: /Library/Developer/CoreSimulator/Volumes/iOS_22E238/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftWebKit.dylib: Operation not permitted

Happening on 18.4 for me as well.

Using 18.6 worked for me.

Confirmed that when the iOS 18.6 simulator is installed it seems to fix general simulator usage (even on iOS 17 simulators). However, #Previews still do not work:

CouldNotFindLibrary: Could not find library with name ”/usr/lib/swift/libswiftWebKit.dylib“

Xcode 16.4 iOS 18.5 simulator crashes for Apps requiring webkit
 
 
Q