【问题标题】:Pod install has required target membership uncheckedPod 安装要求未选中目标成员资格
【发布时间】:2022-02-04 20:00:41
【问题描述】:

问题

如何配置 cocoapods 以便运行 pod install 导致情节提要中 ProjectName 检查目标成员身份

背景

我有一个框架和一个应用程序,它们都是由我的公司创建的。我们使用 Artifactory 和 Cocoapods 来部署框架并将其拉入应用程序。该框架包含一个故事板,然后应用程序使用该故事板来呈现一个表单。我正在使用 XCode 8

由“pod install”创建的 Pod 目标

  • 项目名称
  • 项目名称-项目名称
  • Pods-ProjectNameTest

问题

问题是运行 'pod install' 创建的目标必须手动更新。

框架中的情节提要仅检查了 ProjectName-ProjectName 的目标成员资格。如果我运行该应用程序,我会收到以下异常:

*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“在捆绑包 NSBundle 中找不到名为“ProjectName”的情节提要...

调用代码

let bundle = NSBundle.init(forClass: ProjectNameViewController.classForCoder())]
let storyboard = UIStoryboard(name: "ProjectName", bundle: bundle)

解决方法

如果我手动转到情节提要并检查 ProjectName 的目标成员资格,这将按预期工作。

吊舱规格

用于部署框架

Pod::Spec.new do |spec|

  spec.name     = 'ProjectName'
  spec.version  = '0.3.1'
  spec.license  = { :type => "MIT", :file => "LICENSE" }
  spec.summary  = 'Summary.'
  spec.homepage = 'http://COMPANYWEBSITE'
  spec.authors  = 'Author'
  spec.source   = { :git => 'https://github.com/ProjectName.git',
                    :tag => spec.version.to_s, :submodules => true }
  spec.requires_arc = true
  spec.ios.deployment_target = '8.2'

  spec.framework        = 'Foundation, UIKit'
  spec.source_files     = 'ProjectName/**/*.{swift}'
  spec.resource_bundle = { 'ProjectName' => ['ProjectName/Resources/**/*'] }

end

播客文件

用于将框架拉入应用程序

use_frameworks!

plugin 'cocoapods-art', :sources => [
  'companyname-public'
]

target 'ProjectNameTest' do
  pod 'ProjectName'
end 

【问题讨论】:

  • 我能够通过更改解决此问题:spec.resource_bundle = { 'ProjectName' => ['ProjectName/Resources/**/*'] } 到 spec.resources = 'ProjectName/Resources/ **/*'

标签: ios xcode cocoapods


【解决方案1】:

我可以通过更改来解决这个问题:

spec.resource_bundle = { 'ProjectName' => ['ProjectName/Resources/**/*'] } 

spec.resources = 'ProjectName/Resources/**/*'

【讨论】:

    【解决方案2】:

    不需要解决方法,CocoaPods 自己处理 当你添加

     s.resource_bundles = {
        'ProjectName' => ['ProjectName/Classes/**/*.{xib,storyboard,lproj,plist,json}']
      }
    

    CocoaPods 自动将匹配的文件添加到资源包中, 因为在您的情况下,您必须手动添加它 ,这意味着它与您在 podspec 中提供的路径不匹配

    由于您是 podspec,因此资源包中没有提到情节提要

    spec.resource_bundle = { 'ProjectName' => ['ProjectName/Resources/**/*'] }
    

    尝试将上述更改为

    spec.resource_bundle = { 'ProjectName' => ['path where storyboard or the resource you want to use is'] }
    

    在大多数情况下,这应该可以工作

     s.resource_bundles = {
        'ProjectName' => ['ProjectName/Classes/**/*.{xib,storyboard,lproj,plist,json}']
      }
    

    podfile 不需要更改

    现在为了获取它,创建一个 Helper 类,如下所示

    final class MySDKBundleProvider {
        static let resourceBundle: Bundle = {
            let myBundle = Bundle(for: MySDKBundleProvider.self)
    
            guard let resourceBundleURL = myBundle.url(
                forResource: "ProjectName", withExtension: "bundle")
                else { fatalError(" not found!") }
    
            guard let resourceBundle = Bundle(url: resourceBundleURL)
                else { fatalError("Cannot access ProjectName.bundle!") }
    
            return resourceBundle
        }()
        
    

    它既可以处理pod的静态链接,也可以处理动态链接

    【讨论】:

      【解决方案3】:

      它不起作用的根本问题是命名冲突。您的resource_bundle 与模块同名,因此创建了一个ProjectName-ProjectName 包。

      如果您将 podspec 中的 resource_bundle 重命名为其他名称,它将起作用,并且您不会依赖已弃用的 resources 参数:

      spec.resource_bundle = { 'SomethingElse' => ['ProjectName/Resources/**/*'] }
      

      这将创建一个ProjectName-SomethingElse 包。

      我从这个答案中得到了提示:https://stackoverflow.com/a/70763171/4755172

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-08
        相关资源
        最近更新 更多