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

33.5k views Asked by At

I have problems running a project in Xcode 5.0.2

I get the following error:

dyld: Library not loaded: @rpath/XCTest.framework/Versions/A/XCTest
  Referenced from: /Users/chris/Library/Developer/Xcode/DerivedData/relatio-cwlmozvklaldmictbbjthzuoxnxz/Build/Products/Debug/relatio.app/Contents/MacOS/relatio

Reason: image not found (lldb)

How do I solve this issue?

16

There are 16 answers

2
user637338 On

This is how I solved the problem:

  1. Navigate to the project's "Build Settings"
  2. Search for "Runpath Search Paths"
  3. Enter the following path in the column below the product name: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/
0
Clean Coder On

Go to General > Targets (Left side).

You might have 2nd item containing the word test/s. Click it.

In this general settings > Testing > Host application > Select from options (your app name). That's it!

0
Chris Hanson On

The problem here is that, according to the dyld error message you posted, your application is linking against XCTest.framework. That's incorrect; only your test bundle needs to link against XCTest.framework since only your test bundle contains tests.

4
Robert Wagstaff On

It looks like your main target is linking to XCTest.framework as well as your test target. It should only be linked to the main target.

1) Go to Project settings

2) Go to your apps main target -> other linker flags

3) remove '-framework XCTest'

4) make sure the 'other linker flags' field for your test target still contains '-framework XCTest'

1
Eironeia On

Just for the ones that came up with the same issue:

Check on the lateral right menu which has to look like that:

Should be

And has not have to look like that:

Shouldn't be

0
Ashok Natarajan On

enter the reference of your framework on framework search path AND Run path search path under "Build Settings"---...Now all set to invoke your projects by using import

0
Ted On

For our case, we want to use Mockingjay for both app target and test target

target 'MyProject' do
  pod 'Mockingjay/Core'
  # all pods that are not test go here

  target 'MyProjectTest' do
      inherit! :search_paths
      pod 'Mockingjay/XCTest'
      pod 'Quick', ' ~> 0.9.2'
      # .. all test pods go here
  end
end
0
William Hu On

I have same issue is because i add a new file into the framework. So just run "pod install" solved my issue. But make sure your pod under Tests target too.

0
Rogare On

In my main Target's "Link Binary With Libraries" (under Build Phases), it was the testing framework I was using (Nimble.framework) that was causing the problem. Removed it, and everything's fine!

4
Leszek Zarna On

I had similar problem with OCMock library and solution is:

target :"Application Tests", :exclusive => true do
    pod 'OCMock'
end
0
CommaToast On

I had this error using ios-snapshot-test-case v5.0.2 via Carthage. The problem is related to XCode 11. Apple renamed libswiftXCTest.dylib to libXCTestSwiftSupport.dylib and added XCTest.swiftmodule which has the same symbols in it and can work in place of the old one. But Apple forgot to tell iOS 11.x simulators about this change.

So you need to fix the older iOS version simulators. Here is the terminal command that fixed it for me:

sudo zsh -c ' sourcedir="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib"; 
targetdir="/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 11.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib"; 
ln -s $sourcedir/libXCTestSwiftSupport.dylib $targetdir/libswiftXCTest.dylib;
ln -s $sourcedir/XCTest.swiftmodule $targetdir/XCTest.swiftmodule'

See my comment here: https://github.com/CocoaPods/CocoaPods/issues/9165#issuecomment-573523322

2
milczi On

In my case It was RxTests added by Swift Package Manager to main application target. In pods you decide which Rx components add to which target, but SPM adds it all to main target as default.

0
fearmint On

I ran into this error by renaming my targets one of which was a testing target. After reading the other answers I realized that my Build Phases > Compile Sources was including test classes as compile sources for non-test targets which then tried to import the XCTest framework.

Removing the test classes from my regular target’s Compile Sources solved this for my case.

0
aclima On

If you are using cocoapods, double check that the default_subspec (which by omission includes all available subspecs) does not accidentaly bundle XCTest, e.g. For the following .podspec

Pod::Spec.new do |s|
  s.name = 'MySpec'
  # ... spec definition details

  # "Normal" subspecs

  s.subspec 'NormalSubspec1' do |subspec|
      # ... subspec details
  end

  s.subspec 'NormalSubspec2' do |subspec|
      # ... subspec details
  end
  
  # Testing subspec

  s.subspec 'TestingSubspec' do |subspec|
      subspec.frameworks = 'XCTest'
      # ... subspec details
  end
end

if you were to depend on it in a Podfile as

target 'MyTarget' do
   pod 'MySpec'
end

it would include all subspecs (MySpec/NormalSubspec1, MySpec/NormalSubspec2, and MySpec/TestingSubspec).

Whereas, if you also define default_subspec, then you can exclude MySpec/TestingSubspec from the default dependency.

Pod::Spec.new do |s|
  s.name = 'MySpec'
  # ... spec definition details

  s.default_subspec = 'NormalSubspec1', 'NormalSubspec2'

  # "Normal" subspecs

  s.subspec 'NormalSubspec1' do |subspec|
      # ... subspec details
  end

  s.subspec 'NormalSubspec2' do |subspec|
      # ... subspec details
  end
  
  # Testing subspec

  s.subspec 'TestingSubspec' do |subspec|
      # ... subspec details
      subspec.frameworks = 'XCTest'
  end
end

and it would now behave the same way as if you had explicity dependend on the subspecs

target 'MyTarget' do
   pod 'MySpec/NormalSubspec1'
   pod 'MySpec/NormalSubspec2'
end
0
Hot'n'Young On

I solved this problem this way. I have edited scheme, at "Build" tab ticked "Run".

enter image description here

0
Rem-D On

A solution that worked for me was changing your test target's inherit attribute in your Podfile from :search_paths to :complete. Although this answer suggests that :search_paths is designed for test environments.

target 'myapp' do    
  use_frameworks!

  target 'myappTests' do
    #inherit! :search_paths
    inherit! :complete
  end

end