Rob
Rob

Reputation: 4224

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

I'm willing to add unit and UI tests to my app.

I first configured unit tests with success, I tried to do the same with UI tests. Here is my Podfile, after adding a new UI Testing Bundle target :

platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!

def shared_pods
pod 'Bolts'
pod 'Branch'
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
pod 'GoogleAnalytics'
pod 'GooglePlaces'
pod 'Parse'
pod 'Toast-Swift'
end

target 'MyTarget' do
shared_pods
end

target 'MyTargetUITests' do
shared_pods
end

target 'MyTargetUnitTests' do
shared_pods
end

However, when I try to run the automatically created MyProjectUITests test case, which only contains the basic setup and without even a @testable import MyProject:

import XCTest

class MyProjectUITests: XCTestCase {

    override func setUp() {
        continueAfterFailure = false
        XCUIApplication().launch()
    }
}

I'm getting this error:

Running tests... The bundle “MyProjectUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.

(dlopen_preflight(/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/MyProjectUITests): Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib

Referenced from: /private/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/Frameworks/Toast_Swift.framework/Toast_Swift

Reason: image not found)

What is wrong? Thanks for your help.

EDIT : for information, it works fine when I remove that Toast_swift pod from my UI test target and let it only in my app and unit test targets.

Upvotes: 4

Views: 4187

Answers (3)

LuisCien
LuisCien

Reputation: 6432

I too faced this issue and none of the other suggestions worked.

After a while I found out that specifically using print() anywhere in your code will somehow force libswiftSwiftOnoneSupport.dylib to be loaded and the issue will go away.

I'm using Xcode 10.1, Swift 4.2 and the pod that was giving me this issue was Nimble.

Hope this helps!

Upvotes: 0

zvjerka24
zvjerka24

Reputation: 1792

Try adding inherit! :search_paths

and 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

Upvotes: 0

Jon Vogel
Jon Vogel

Reputation: 5634

Check out this issue on the cocoapods github issue tracker.

I'm still a little confused as to why this became a problem but the setting the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to YES using this script fixed the issue for me.

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            # This works around a unit test issue introduced in Xcode 10.
            # We only apply it to the Debug configuration to avoid bloating the app size
            if config.name == "Debug" && defined?(target.product_type) && target.product_type == "com.apple.product-type.framework"
                config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = "YES"
            end
        end
    end
end 

Upvotes: 6

Related Questions