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

20

87

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.

Menial answered 8/11, 2016 at 6:40 Comment(1)
This is happening to me when i imported a framework which is added via SPM in my UI tests code. Already tried adding the package to the UITest target under build phases > Link Binary with Libraries but didn't workKirakiran
O
32

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.

Oahu answered 16/9, 2018 at 15:2 Comment(11)
if there were multiple pods, what would be the syntax?Procarp
@RomanPodymov i have same above issue using CocoaPods 1.5.3 This is my pod file, # Uncomment the next line to define a global platform for your project platform :ios, '9.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 'SwiftMessages' pod 'IQKeyboardManager' pod 'AlamofireImage' . pod 'Alamofire' target 'MyAppUITests' do inherit! :search_paths # Pods for testing end endSide
Hello @JibranSiddiQui. Try to remove inherit! :search_paths from target 'MyAppUITests'. Or do you need to keep it?Oahu
Hi thanks for your comment, @RomanPodymov i tried without inherit! :search_paths but not working, and i also have other CocoaPods lib to beside these mentions. i haven't any idea of uitest before.Side
Hello @JibranSiddiQui. I tried to install all these pods and I've got no error. What version of Xcode are you using? Do you have Objective-C or Swift project?Oahu
@RomanPodymov I am using swift and here are my pods pod 'SwiftMessages' pod 'SwiftKeychainWrapper' pod 'Tabman' pod 'PagingMenuController' pod 'Kingfisher' pod 'Optik' pod 'KRPullLoader' pod 'AlamofireImage' pod 'Firebase/Core' pod 'Firebase/Database' pod 'Firebase/Messaging' pod 'Firebase/Auth' pod 'Firebase/Storage' pod 'TCPickerView' pod 'GoogleMaps' pod 'GooglePlaces' pod 'Whisper' pod 'Fabric' pod 'Crashlytics' pod 'SwiftyJSON' pod 'Alamofire' pod 'SwiftGridView' now please trySide
Hello @JibranSiddiQui. What version of Xcode are using? I was able to reproduce this issue in Xcode 9.4, but since I use Xcode 10.1 everything works fine. Try to update your Xcode instance.Oahu
@JibranSiddiQui I updated my answer. Please check it.Oahu
@Procarp Please check this answer https://mcmap.net/q/243360/-the-bundle-uitests-couldn-t-be-loadedbecause-it-is-damaged-or-missing-necessary-resources-try-reinstalling-the-bundle , it resolves the issue that you mentioned.Oahu
Thank you. Are there any unintended consequences that can come from this? I got some Swift warnings: "An iOS Deployment Target earlier than 8.0 is not supported by this version of Xcode. This will update the value for Target 'nanopd' to '8.0' and also the iOS simulator deployment target iPhones_deployment_target is set to 4.3 but the range of of supported deployment target versions is 8.0 to 13.2.99?Lavalley
@Lavalley I think this is a known issue.Oahu
D
23

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
Daryn answered 11/12, 2017 at 14:14 Comment(1)
In addition to using this solution, I also found that at least one source file that's visible to your tests target needs to have import <Pod> (in this case, import Alamofire) in order to fix the error.Overthrow
L
22

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

Loculus answered 27/7, 2019 at 22:34 Comment(0)
A
15

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.

Alkahest answered 16/10, 2018 at 17:29 Comment(0)
G
15

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
Ginglymus answered 12/3, 2019 at 4:26 Comment(1)
Only the last solution works for me as well. I didn't have to move the use_frameworks! inside the target, though, I left it on the top and it works fine. All the other changes were needed.Tithing
M
9

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

Mychal answered 20/6, 2018 at 8:36 Comment(0)
I
7

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

Illusionary answered 18/7, 2019 at 11:40 Comment(0)
P
3

Xcode testing problem

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

Psychro answered 13/11, 2020 at 17:47 Comment(1)
This worked for me. My UI Test Bundle was not loading and it didn't recognized a xcframework. Doing this worked. Thanks!Centre
T
2

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

Totipalmate answered 4/1, 2019 at 16:30 Comment(0)
N
2

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.

Norvin answered 9/3, 2020 at 16:12 Comment(0)
M
1

1

2[![3]3

  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
Menial answered 17/11, 2016 at 4:12 Comment(2)
question doesn't mention that they use CocoapodsRheingold
what happend when you are using carthage, wrong answer.Subteen
K
1

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

Kharkov answered 13/12, 2018 at 13:42 Comment(1)
But what if you need UI tests in your project?Oahu
N
1

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

Nickola answered 12/11, 2019 at 23:53 Comment(0)
S
1

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

Sisneros answered 2/12, 2019 at 19:2 Comment(0)
H
1

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
Helms answered 5/1, 2020 at 17:13 Comment(0)
L
0

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!!

Lola answered 16/4, 2019 at 19:8 Comment(0)
D
0

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.

Dna answered 12/12, 2019 at 12:38 Comment(0)
C
0

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

Crossgarnet answered 27/9, 2021 at 8:32 Comment(0)
A
-1

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

Anson answered 17/11, 2019 at 15:57 Comment(0)
M
-5

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

Mikaelamikal answered 1/12, 2017 at 2:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.