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

16

43

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?

Incidental answered 1/12, 2013 at 23:5 Comment(2)
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/Incidental
You can answer your own question by writing an answer instead of a comment.Isotropic
C
28

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'

Cornu answered 11/8, 2014 at 21:2 Comment(4)
I followd this. but not helpedExpediential
Good answer, but what I have there is $(inherited) to bring in the data from CocoaPods.Cathee
Instead of removing, you can also make your framework optional by doing -weak_framework "XCTest"Egest
I don't have test target anymore, I've removed it from the app. Still I'm getting the same error.Commode
N
19

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.

Neutrality answered 4/7, 2014 at 15:26 Comment(0)
G
12

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

enter image description here

Gine answered 31/8, 2016 at 10:52 Comment(0)
H
8

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.

Hendricks answered 1/1, 2014 at 19:7 Comment(0)
Z
6

I had similar problem with OCMock library and solution is:

target :"Application Tests", :exclusive => true do
    pod 'OCMock'
end
Zinciferous answered 30/9, 2014 at 8:35 Comment(4)
For those dummies like me, if your application is named MyApp, the target here is MyAppTests ...Mousse
Careful, if you do 'exclusive => true' you are NOT including any more pods from other targets.Egest
Note that :exclusive has since been replaced with inherit! :search_paths. See blog.cocoapods.org/CocoaPods-1.0-Migration-GuideGlassine
@LeszekZarna Sure, I added the post 1.0 syntax to your existing example.Glassine
A
5

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.

Antalkali answered 15/1, 2020 at 20:43 Comment(2)
Yes I removed from the main target and it works fine now. ThanksConsolata
I moved RxTest pod to test target in Podfile then deleted Xcode Derived data, then the problem solved.Yonah
I
4

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/
Incidental answered 4/12, 2013 at 21:23 Comment(2)
This is incorrect in a couple of ways. First, it will lead to a dependency of your application on XCTedt.framework, which is only available within Xcode. Second, you're using an absolute path, which isn't guaranteed to be the same from Mac to Mac (for example if you have multiple versions of Xcode installed).Hendricks
@ChrisHanson: This is really working with Xcode 5.1.1. But note that you don't need to provide Absolute Path, relative path should be provided. My scenario was, I have build Dynamic Frameworks with Xcode 6, then i tried to used it in Xcode 5.1.1 in my application, I received same issue describe here... I tried giving path of my Dynamic framework in "Runpath Search paths" and it worked..Schade
C
2

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!

Cayenne answered 5/3, 2016 at 13:39 Comment(0)
B
1

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

Bellicose answered 31/8, 2015 at 15:37 Comment(0)
D
1

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.

Dorren answered 25/12, 2015 at 3:17 Comment(0)
P
0

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

Prominent answered 4/12, 2018 at 14:55 Comment(1)
You could probably explain that applies for all and only your test files.Polymerize
S
0

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
Sandrocottus answered 2/3, 2019 at 1:9 Comment(0)
L
0

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
Lark answered 7/8, 2019 at 19:3 Comment(0)
D
0

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

Danielldaniella answered 13/1, 2020 at 19:12 Comment(0)
S
0

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!

Sitzmark answered 27/9, 2020 at 2:8 Comment(0)
S
0

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
Sagittal answered 5/4, 2023 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.