3

I'm trying to run a UI Test in my app but as soon as the simulator launches I get:

The bundle “AppUITests” couldn't be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.

2018-10-05 11:04:59.772078-0500 AppUITests-Runner[53273:1645870] (dlopen_preflight(/Users/John/Library/Developer/Xcode/DerivedData/app-ios-client-ewtlrcqcxoeiaudgmthymuhcuxfz/Build/Products/Debug-iphonesimulator/AppUITests-Runner.app/PlugIns/AppUITests.xctest/AppUITests): Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib Referenced from: /Users/John/Library/Developer/Xcode/DerivedData/app-ios-client-ewtlrcqcxoeiaudgmthymuhcuxfz/Build/Products/Debug-iphonesimulator/AppUITests-Runner.app/PlugIns/AppUITests.xctest/Frameworks/Alamofire.framework/Alamofire Reason: image not found)

My UITest is the template created by Xcode 10, I'm using Cocoapods 1.5.3 and Swift 4.2

My project structure:

  • Workspace
    • Custom Framework (The Podfile is here)
    • App A (Here I'm running the UITests)
    • App B

My podfile looks like this:

platform :ios, '10.0'

inhibit_all_warnings!
use_frameworks!

target 'App Library' do
    use_frameworks!

    pod 'Intercom'
    pod 'Spreedly'
    pod 'Alamofire'
    pod 'IGListKit'
    pod 'CardIO'
    pod 'SwiftKeychainWrapper'
    pod 'OneTimePassword', :git =>   'https://github.com/john/OneTimePassword.git', :branch => 'develop'
    pod 'SnapKit'
    pod 'DateToolsSwift'
    pod 'BetterSegmentedControl'
    pod 'SDWebImage'
    pod 'SwiftLocation'
    pod 'Nuke'
    pod 'Instabug'
    pod 'Mixpanel-swift'


    target 'App LibraryTests' do
        inherit! :search_paths
        # Pods for testing
    end

    target 'App' do
        project '../App/App'
        inherit! :complete

        use_frameworks!

        pod 'FacebookCore'
        pod 'FacebookLogin'

        target 'AppTests' do
            inherit! :search_paths
            # Pods for testing
        end
    end

    target 'App Business' do
         project '../App Business/App Business'
         inherit! :complete

         use_frameworks!

         target 'App BusinessTests' do
             inherit! :search_paths
             # Pods for testing
         end

         target 'App BusinessUITests' do
             inherit! :search_paths
             # Pods for testing
         end
     end

end

# The UI Test target I'm trying to run
target 'AppUITests' do
     inherit! :search_paths
     use_frameworks!
     # Pods for testing
     project '../App/App'
     pod 'Intercom'
     pod 'Spreedly'
     pod 'Alamofire'
     pod 'IGListKit'
     pod 'CardIO'
     pod 'SwiftKeychainWrapper'
     pod 'OneTimePassword', :git => 'https://github.com/john/OneTimePassword.git', :branch => 'develop'
     pod 'SnapKit'
     pod 'DateToolsSwift'
     pod 'BetterSegmentedControl'
     pod 'SDWebImage'
     pod 'SwiftLocation'
     pod 'Nuke'
     pod 'FacebookCore'
     pod 'FacebookLogin'
     pod 'Instabug'
     pod 'Mixpanel-swift'
end

workspace '../app-ios-client'

I have tried putting the UI test target inside the target app with !inherit:complete and !inherit:search_paths, moving it outside like in the code posted above. I have also cleaned the build folders, deleted derived data and restarted Xcode and I still have this problem. I have also tried adding import UIKit and import Alamofire and nothing has worked. Between all this possible fixes I have run pod deintegrate followed by pod install. I think the problem may be related to the podfile being inside my custom framework but honestly I have no idea. Any ideas? Thank you!

Lalo
  • 383
  • 2
  • 8
  • Does this answer your question? [Xcode 10 - UITests - Reason: image not found](https://stackoverflow.com/questions/52566702/xcode-10-uitests-reason-image-not-found) – Top-Master Jul 20 '21 at 10:01

3 Answers3

5

My fix was similar to https://stackoverflow.com/a/54034832/883413 except I didn't bother with the post_install section.

Previously my podfile structure was similar to that in the question:

platform :ios, '10.0'

target 'AppName' do
  use_frameworks!
  
  pod 'PodName'

  target 'AppNameTests' do
    inherit! :search_paths
  end

  target 'AppNameUITests' do
    inherit! :search_paths
  end
end

Changing it to (the newer?) structure like this resolved the issue:

platform :ios, '10.0'
use_frameworks!

def all_pods
  pod 'PodName'
end

target 'AppName' do
  all_pods
end
  
target 'AppNameTests' do
  inherit! :search_paths
  all_pods
end

target 'AppNameUITests' do
  inherit! :search_paths
  all_pods
end

Ric Santos
  • 15,419
  • 6
  • 50
  • 75
2

I fixed it by changing that target in my podfile to this:

target 'AppUITests' do
    inherit! :search_paths
    use_frameworks!
    # Pods for testing
    project '../App/App'
end
Lalo
  • 383
  • 2
  • 8
1

Try beside of adding inherit! :search_paths

also changing ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES in post_install

use_frameworks!

def shared_pods
    pod 'SomePod'
end

target 'App_name' do
    shared_pods
end

target 'App_nameTests' do
    inherit! :search_paths
    shared_pods
end

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
        end
    end
end
zvjerka24
  • 1,772
  • 1
  • 21
  • 27