Xcode 10 UI测试:Cocoapods出现“图像未找到”错误的原因

3

我正在尝试在我的应用程序中运行UI测试,但是一旦模拟器启动,我就会收到以下信息:

捆绑包“AppUITests”无法加载,因为它已经损坏或缺少必要的资源。请尝试重新安装该捆绑包。

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)

我的UITest是由Xcode 10创建的模板,我使用Cocoapods 1.5.3和Swift 4.2

我的项目结构如下:

  • 工作区
    • 自定义框架(Podfile在此处)
    • 应用程序A(我在这里运行UITests)
    • 应用程序B

我的Podfile如下所示:

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'

我尝试将 UI 测试目标使用 !inherit:complete!inherit:search_paths 放在应用程序目标内部,也像上面发布的代码一样将它移动到外部。我还清理了构建文件夹,删除了派生数据并重新启动了 Xcode,但仍然存在这个问题。我还尝试添加 import UIKitimport Alamofire,但都没有起作用。在所有可能的修复中,我运行了 pod deintegrate,然后是 pod install。我认为问题可能与 Podfile 在我的自定义框架内部有关,但老实说我不知道。有任何想法吗?谢谢!

这个回答解决了你的问题吗?Xcode 10 - UITests - Reason: image not found - Top-Master
3个回答

5

我的修复方法类似于https://dev59.com/iq7la4cB1Zd3GeqPkuWV#54034832,但我没有关注post_install部分。

之前我的Podfile结构与问题中的类似:

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

将它更改为这样的结构解决了问题:
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


2

我通过将podfile中的目标更改为以下内容来解决了这个问题:

target 'AppUITests' do
    inherit! :search_paths
    use_frameworks!
    # Pods for testing
    project '../App/App'
end

1

除了添加inherit! :search_paths之外,还需在post_install中更改ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接