2

I have an app that can successfully deploy to the simulator and a device, but when I attempt to run its associated UI tests, I am getting the following error:

MY_APP_TARGETUITests-Runner[55293:20696349] The bundle “MY_APP_TARGETUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.

MY_APP_TARGETUITests-Runner[55293:20696349] (dlopen_preflight(/Users/@@@@/Library/Developer/Xcode/DerivedData/MY_APP_TARGET-gbamhqqrrbznxidxekwloacioddy/Build/Products/Debug-iphonesimulator/MY_APP_TARGETUITests-Runner.app/PlugIns/MY_APP_TARGETUITests.xctest/MY_APP_TARGETUITests): Library not loaded: @rpath/libswiftAVFoundation.dylib

Referenced from: /Users/@@@@/Library/Developer/Xcode/DerivedData/MY_APP_TARGET-gbamhqqrrbznxidxekwloacioddy/Build/Products/Debug-iphonesimulator/MY_APP_TARGETUITests-Runner.app/PlugIns/MY_APP_TARGETUITests.xctest/Frameworks/MyLocalPod.framework/MyLocalPod

Reason: image not found)

The first issue appears related to Library not loaded: @rpath/libswiftAVFoundation.dylib, so I looked into that issue with the following:

dyld: Library not loaded: @rpath/libswiftAVFoundation.dylib

I performed the following items to attempt to resolve it:

  • Removed and re-installed the affected pod
  • Clean & rebuild
  • Restart XCode & machine
  • Delete derived data
  • Added s.framework = 'AVFoundation' to the podspec file for my local pod
  • Set Always Embed Swift Standard Libraries to default (my pods now install without any warnings or errors)

Successful pod installation

None of these resolved the first error.

Regarding the second, I also checked here:

XCode10 - UITests - Reason: image not found

My Podfile is set up like this:

use_frameworks!
inhibit_all_warnings!
platform :ios, '10.3'

def default_pods
    pod 'RemotePod', '~> 1.0'
    pod 'MyLocalPod', :path => 'path/to/MyLocalPod'
end

target 'MY_APP_TARGET' do
    default_pods
end

target 'MY_APP_TARGETTests' do
    inherit! :search_paths

    default_pods
end

target 'MY_APP_TARGETUITests' do
    inherit! :search_paths

    default_pods
end

I have tested putting the pod directly into the target, but that did not change things.

Everything involved is 100% Swift, so there should not be any issues regarding mixing Objective-C.

  • 1
    See https://stackoverflow.com/questions/34990175/test-target-x-encountered-an-error-early-unexpected-exit-operation-never-finis for more ideas – Paul Beusterien Dec 29 '18 at 19:05
  • @PaulBeusterien Thanks, I tried those but was not able to find one that worked. However, I did resolve it with another fix. –  Jan 03 '19 at 22:28

2 Answers2

1

This issue is common in cases when one of your framework uses another framework as it's dependency. You should add all the dependencies to your app target directly instead of adding it to framework.

singhabhi13
  • 227
  • 1
  • 7
0

Re-setting the simulator & device fixed it for me.

None of the steps at the link provided by Paul were able to resolve it.