11

My app was running perfectly without any errors or warnings yesterday. But when I tried to run it today, the build failed - I haven't changed anything in the code:

Undefined symbol: __swift_FORCE_LOAD_$_XCTestSwiftSupport

How to fix this, and why would something like this occur suddenly when it was working before?

And this is an issue I've been experiencing with XCode a lot lately. My code will be running smoothly without any errors, but then XCode will randomly start throwing errors when I relaunch it at a different time - without making any changes in the actual code.

enter image description here

enter image description here

ela16
  • 270
  • 1
  • 12
  • 1
    Clear derived data ? Cleaned build ? – amar Nov 09 '21 at 06:46
  • Yes I tried both. – ela16 Nov 09 '21 at 21:52
  • If your code ran fine a few days ago, but suddenly one day it started reporting errors, something must have changed. If it was not a code change, maybe it was Xcode itself, or maybe the project configuration. Be aware of these things. – ziggear Nov 10 '21 at 13:28
  • 1
    So I was able to get rid of the error by going to app settings > Build Phases > Link Binary With Libraries > add the linked library "XCTest.framework". HOWEVER, even though the build succeeds, when the app launches, it aborts: 0_abort_with_payload. And if I remove the library, the build starts failing again. – ela16 Nov 10 '21 at 22:05
  • I solved this other issue by navigating to target app > Build Settings > Linking > Other Linker Flags > editing or adding -weak_framework "XCTest". https://stackoverflow.com/questions/20340763/xcode-5-0-2-dyld-library-not-loaded-rpath-xctest-framework-versions-a-xctest – ela16 Nov 11 '21 at 00:00

3 Answers3

14

This condition also occurs if you add

import XCTest

to a file in a non-test bundle.

Spiff
  • 503
  • 6
  • 9
  • 1
    Omg thank you. Since latest Xcode will automatically add the import statements; I had accidentally created an XCTestCase in my non-test file by accident and it added the import without me realizing it. – Hedylove Feb 22 '22 at 04:05
  • Yes, this can easily happen with Xcode 13 automatic imports. If you mistype something it might import a framework, like XCTest, and you may not know it. That's what happened to me. – Devin Pitcher Mar 28 '22 at 02:41
13

I solved this error by navigation to target app settings > Build Phases > Link Binary With Libraries > add the linked library "XCTest.framework".

If afterwards your app starts crashing, aborting with the following errors:

dyld: Library not loaded: @rpath/XCTest.framework/Versions/A/XCTest

0_abort_with_payload

Then you can take a look at the suggestions on this thread: Xcode 5.0.2 dyld: Library not loaded: @rpath/XCTest.framework/Versions/A/XCTest

The solution that worked for me was: Navigate to target app > Build Settings > Linking > Other Linker Flags > editing or adding -weak_framework "XCTest"

ela16
  • 270
  • 1
  • 12
  • 1
    In my case, after seeing "dyld: Library not loaded: @rpath/XCTest.framework/Versions/A/XCTest", I turned the Status to Optional for the XCTest.framework library under Link Binary With Libraries. That solved the problem. – Cable W Dec 17 '21 at 07:11
  • 1
    This feels like a last resort if nothing else works. It may be harmless, but ideally you don't want to send out your production app with XCTest linked in. It's better to track down the dependency that is causing Xcode to think it needs an XCTest symbol. I think @Spiff's answer pinpoints what is likely the root cause in many cases. – Devin Pitcher Mar 28 '22 at 16:33
5

This error randomly started to occur on my Xcode project today. I changed the setting.

PROJECT -> Build Settings -> Build Options -> Enable Testing Search Paths

from No to Yes, and the build succeeded.

Seamus
  • 809
  • 8
  • 19