Xcode got "Image Not Found" while running the test

308 Views Asked by At

I am trying to add UI Tests to my project using EarlGrey 2.0 by following this steps to install the framework : https://www.youtube.com/watch?v=KQaA11qVQn0 (using Cocoapods). It build successfully but when I tried to run the test, I got this error:

2020-11-27 14:18:16.076586+0700 X-UITests-Runner[75526:5465621] The bundle X-UITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2020-11-27 14:18:16.076704+0700 X-UITests-Runner[75526:5465621] (dlopen_preflight(/X-blqsydhdzeecqndvwzwsshajcwdm/Build/Products/Debug-iphonesimulator/X-UITests-Runner.app/PlugIns/X-UITests.xctest/X-UITests): Library not loaded: @rpath/Alamofire.framework/Alamofire
  Referenced from: /X-blqsydhdzeecqndvwzwsshajcwdm/Build/Products/Debug-iphonesimulator/X-UITests-Runner.app/PlugIns/X-UITests.xctest/X-UITests
  Reason: image not found)

I have this on my podfile:

use_frameworks!

def shared_pods
  pod 'Alamofire'
  pod 'Firebase'
  pod 'Firebase/Analytics'
  pod 'Firebase/RemoteConfig'
  pod 'Firebase/Crashlytics'
  pod 'Firebase/Messaging'
  pod 'Firebase/Auth'
  pod 'Firebase/Database'
  pod 'Introspect'
  pod 'ReachabilitySwift'
  pod 'RealmSwift'
  pod 'SDWebImageSwiftUI'
  pod 'SwiftKeychainWrapper'
  pod 'Zip'
end

target 'X' do
  shared_pods
  pod 'EarlGreyApp'
end

target 'X-UITests' do
  inherit! :search_paths
  pod 'EarlGreyTest'
  pod 'eDistantObject', '0.9.0'
end

I have tried to uncheck the Find Implicit Dependencies on the scheme, but still got the error. Any help? Thanks.

2

There are 2 best solutions below

0
Gopal Kohli On

Try using use_frameworks! next to target,

    def shared_pods
      pod 'Alamofire'
      pod 'Firebase'
      pod 'Firebase/Analytics'
      pod 'Firebase/RemoteConfig'
      pod 'Firebase/Crashlytics'
      pod 'Firebase/Messaging'
      pod 'Firebase/Auth'
      pod 'Firebase/Database'
      pod 'Introspect'
      pod 'ReachabilitySwift'
      pod 'RealmSwift'
      pod 'SDWebImageSwiftUI'
      pod 'SwiftKeychainWrapper'
      pod 'Zip'
    end

    target 'X' do
      use_frameworks!
      shared_pods
      pod 'EarlGreyApp'
    end

    target 'X-UITests' do
      use_frameworks!
      inherit! :search_paths
      pod 'EarlGreyTest'
      pod 'eDistantObject', '0.9.0'
    end
0
Andrew On

This kind of error, in general, says that some class which are you trying to test has dependency to Alamofire pod. So you have to add Alamofire also to your test Target

target 'X-UITests' do
    ...
    pod 'Alamofire'
    ...
end