Reputation: 2665
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?
Upvotes: 43
Views: 34319
Reputation: 780
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
Upvotes: 0
Reputation: 562
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!
Upvotes: 0
Reputation: 7572
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.
Upvotes: 5
Reputation: 12188
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
Upvotes: 0
Reputation: 675
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
Upvotes: 0
Reputation: 23746
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
Upvotes: 0
Reputation: 781
Just for the ones that came up with the same issue:
Check on the lateral right menu which has to look like that:
And has not have to look like that:
Upvotes: 0
Reputation: 2674
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'
Upvotes: 28
Reputation: 491
I solved this problem this way. I have edited scheme, at "Build" tab ticked "Run".
Upvotes: 12
Reputation: 3274
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!
Upvotes: 2
Reputation: 16149
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.
Upvotes: 1
Reputation: 31
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
Upvotes: 1
Reputation: 3317
I had similar problem with OCMock library and solution is:
target :"Application Tests", :exclusive => true do
pod 'OCMock'
end
Upvotes: 6
Reputation: 5334
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.
Upvotes: 19
Reputation: 55116
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.
Upvotes: 8
Reputation: 2665
This is how I solved the problem:
Upvotes: 4