The bundle UITests couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle

IosSwiftTravis CiUitest

Ios Problem Overview


I can't run my test case due to this following errors :

  • The bundle “UITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
  • Library not loaded: @rpath/Alamofire.framework/Alamofire.
  • Reason: image not found

Try searching and solving since two days but couldn't get through this issue can someone please help.

Ios Solutions


Solution 1 - Ios

I was able to reproduce this issue with the project generated by Xcode 10.1. I used Swift 4.2 and CocoaPods 1.10.0 as a dependency manager. I had the following Podfile:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'

target 'MyApp' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyApp
  pod 'Alamofire', '4.8.1'

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

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

end

Then I removed use_frameworks!, see this link for more details:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'

target 'MyApp' do

  # Pods for MyApp
  pod 'Alamofire', '4.8.1'    

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

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

end

I also received some warnings like this:

[!] The `MyAppUITests [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-MyApp-MyAppUITests/Pods-MyApp-MyAppUITests.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

That's why I removed this line from the MyAppUITests build settings:

MyAppUITests build settings

After that run pod deintegrate && pod install and then the problem disappeared. Probably for projects with more dependencies (like here) you need to use another solution.

Solution 2 - Ios

It's because your pods only apply to your Framework target and no the tests one. Add the tests target to your podfile.

Example :

target 'MyFramework' do
  use_frameworks!
  pod 'Alamofire', '~> 4.5'
end

target 'MyFrameworkTests' do
  use_frameworks!
  pod 'Alamofire', '~> 4.5'
end

Solution 3 - Ios

In your tests target change inherit! :search_paths to inherit! :complete. See the documentation for what this does.

Solution 4 - Ios

Check that the deployment target in your UITest target Build Settings is set to the same as the host application you are trying to test. In my case, I added the UITesting target later on, and it created it with a default of deployment target iOS 12. If you then try to run the UITest on iOS lower than 12, it gave me the error mentioned in the question.

Solution 5 - Ios

In my case, I needed to separate the UI tests target with use_frameworks!.

Moving the UI tests target from nested structure to its own will not help, if you specified use_frameworks! globally somewhere in the top of the Podfile.

The Podfile with error (original):

platform :ios, '10.0'

inhibit_all_warnings!
use_frameworks!

target 'MyProject' do
  pod 'R.swift', '~> 5.0'
  pod 'Moya/RxSwift', '~> 12.0'
  # and other pods

  target 'MyProjectTests' do
    inherit! :search_paths

    pod 'iOSSnapshotTestCase', '~> 6.0'
  end

  target 'MyProjectUITests' do
    inherit! :search_paths
  end
end

The Podfile with error (first try to fix):

platform :ios, '10.0'

inhibit_all_warnings!
use_frameworks!

def shared_pods
  pod 'R.swift', '~> 5.0'
end

target 'MyProject' do
  shared_pods

  pod 'Moya/RxSwift', '~> 12.0'
  # and other pods

  target 'MyProjectTests' do
    inherit! :search_paths

    pod 'iOSSnapshotTestCase', '~> 6.0'
  end
end

target 'MyProjectUITests' do
  shared_pods
end

The final working Podfile:

platform :ios, '10.0'

inhibit_all_warnings!

def shared_pods
  pod 'R.swift', '~> 5.0'
end

target 'MyProject' do
  use_frameworks!

  shared_pods

  pod 'Moya/RxSwift', '~> 12.0'
  # and other pods

  target 'MyProjectTests' do
    inherit! :search_paths

    pod 'iOSSnapshotTestCase', '~> 6.0'
  end
end

target 'MyProjectUITests' do
  shared_pods
end

Solution 6 - Ios

I had to add the location of my frameworks to Runpath search Path under targets>mytestTarget>Build Settings>Runpath Search Path

Solution 7 - Ios

This error happened to me when I added a framework to the project (that's a framework itself, too), and tried to run the tests. I made it optional instead of required, and the tests succeeded. enter image description here

Solution 8 - Ios

Switching to legacy build system fixed thi issue with Xcode 10.

Solution 9 - Ios

For anyone encountering this issue using Carthage, I solved it by adding the /usr/local/bin/carthage copy-frameworks run script phase to the UITest target (rather than just my main app target), and added the framework as an input file.

Solution 10 - Ios

1

[23

  1. Go To Build Phases
  2. Open Copy Pods Resources and copy the path
  3. Paste the path that you have copied from Copy Pods Resources and change tag name resources with frameworks
  4. Clean and Build
  5. Run your UITestsFile

Solution 11 - Ios

What solved my problem was following the following steps:

  1. delete the UITests target from the pod file. Initially, I had the following in the pod file:

    target 'XUITests' do inherit! :search_paths
    end

  2. Deintegrate the pods (with pod deintegrate)

  3. Install the pods (with pod install)

  4. Clean your project and run the project or your UITest

Solution 12 - Ios

Xcode 11.2 using Apollo framework within another framework. Instead of changing to optional/required, I fixed it by setting to embed.

With this specific error:

> The bundle “XXX” couldn’t be loaded because it is damaged or missing > necessary resources. Try reinstalling the bundle. Library not loaded: > @rpath/Apollo.framework/Apollo

I had to embed the framework

enter image description here

Solution 13 - Ios

In my case, just removing inherit! :search_paths without changing the structure of the file or duplicating any pod fixed my problem.

Solution 14 - Ios

I saw the answer but without an explanation so decided to post mine.

The issue is that UI tests performed in a separate application that controls the main one and so it can't use the main application's frameworks and so if you just inherit paths to frameworks using Cocoapods UI tests app will crash at the startup.

To fix the issue you need to actually copy frameworks to UI tests app or update your Podfile:

use_frameworks!
target 'App' do
  pod 'Alamofire'
  
  target 'App_UnitTests' do
    inherit! :search_paths
    
    pod 'Quick'
    pod 'Nimble'
  end
end

target 'App_UITests' do
  pod 'Alamofire'
end

Solution 15 - Ios

The bundle UITests couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle

I have run on this problem when tried to run UI Testing Bundle for testing a Framework

The solution is simple:

Build Phases -> + -> New Copy Files Phase -> <select a framework> -> Destination Frameworks 

enter image description here

As a result <UI_Testing_Bundle_name>-Runner.app is generated

Solution 16 - Ios

For me, the error was when build the UITests. The solution: The Targer was with a wrong iOS version, I replace with the same version that the tested Target and everything works!!

Solution 17 - Ios

For me, this problem was caused by me referencing a property from an extension on a UIKit class from a framework which wasn't imported in the file where it was referenced. Fixed by not using that property. I'm not sure why it compiled in the first place - that should have been a compile-time error, not a runtime error.

Solution 18 - Ios

In my case simply choosing "My Mac" instead of "My Mac (Mac Catalyst)" allowed me to run the tests.

Solution 19 - Ios

Try copy every pod for your app target to the UI testing target. 2019 it works.

Solution 20 - Ios

If you are in fact using Cocoapods, you probably just need to run "pod install" and the build settings will be updated automatically.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2273146View Question on Stackoverflow
Solution 1 - IosRoman PodymovView Answer on Stackoverflow
Solution 2 - IosAnthonyView Answer on Stackoverflow
Solution 3 - IosRem-DView Answer on Stackoverflow
Solution 4 - IosSamuëlView Answer on Stackoverflow
Solution 5 - IosShyngys KassymovView Answer on Stackoverflow
Solution 6 - IosMartin O'SheaView Answer on Stackoverflow
Solution 7 - IosDisplay NameView Answer on Stackoverflow
Solution 8 - IosYMonnierView Answer on Stackoverflow
Solution 9 - IosFrothSturgeonView Answer on Stackoverflow
Solution 10 - Iosuser2273146View Answer on Stackoverflow
Solution 11 - IosMelkonView Answer on Stackoverflow
Solution 12 - IosMochaView Answer on Stackoverflow
Solution 13 - IosJeremy CochoyView Answer on Stackoverflow
Solution 14 - IosAnton PlebanovichView Answer on Stackoverflow
Solution 15 - IosyoAlex5View Answer on Stackoverflow
Solution 16 - IosNarlei MoreiraView Answer on Stackoverflow
Solution 17 - IosOlethaView Answer on Stackoverflow
Solution 18 - IosPaulius LiekisView Answer on Stackoverflow
Solution 19 - IosFitsyuView Answer on Stackoverflow
Solution 20 - IosdavidgoliView Answer on Stackoverflow