使用Swift和Objective-C构建Cocoapod:如何处理Umbrella Header问题?

3
我有一个现有的 Xcode 框架,使用了 Swift 和 Objective-C,我正在尝试将其作为 Cocoapod 运行。 我目前的步骤如下:
1) 我使用 pod lib create SMCoreLib 初始化了一个新文件夹 (https://guides.cocoapods.org/making/using-pod-lib-create.html)。
2) 我将我的框架中的 Swift 和 Objective-C 代码复制到这个新初始化的 pod 文件夹中的 SMCoreLib/Classes 文件夹中。 我还将此代码拖入 _Pods.xcodeproj 中的相关组中。
3) 我对我的项目的 .podspec 文件进行了一些更改。 它如下所示(请注意,Github 存储库尚未更新这些更改;如果需要,我可以进行更新):
Pod::Spec.new do |s|
  s.name             = 'SMCoreLib'
  s.version          = '0.0.2'
  s.summary      = 'Spastic Muffin Core Library for iOS'

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!

  s.description      = <<-DESC
    Objective-C and Swift classes to support Spastic Muffin code.
                       DESC

  s.homepage     = "https://github.com/crspybits/SMCoreLib.git"
  s.license      = { :type => "GPL3", :file => "LICENSE.txt" }
  s.author             = { "Christopher Prince" => "<snip>" }

  s.platform     = :ios, "8.0"

  s.source       = { :git => "https://github.com/crspybits/SMCoreLib.git", :tag => "#{s.version}" }

  s.ios.deployment_target = '8.0'

  s.source_files = 'SMCoreLib/Classes/**/*'

  s.resources = "SMCoreLib/Assets/**"

  # s.resource_bundles = {
  #   'SMCoreLib' => ['SMCoreLib/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'

  s.requires_arc = true

  # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }

  s.dependency 'AFNetworking'
  s.dependency 'HPTextViewTapGestureRecognizer', '~> 0.1'
  s.dependency 'Reachability'
end

我的问题是我在尝试构建Example Xcode项目和尝试对Pod进行lint时都失败了。构建Example Xcode项目时,我遇到以下错误:Xcode errors。当我在命令行中执行以下操作时:
pod lib lint --allow-warnings --verbose --no-clean

我遇到了以下错误:

- NOTE  | [iOS] xcodebuild:  <module-includes>:2:9: note: in file included from <module-includes>:2:
- ERROR | [iOS] xcodebuild:  /Users/chris/Library/Developer/Xcode/DerivedData/App-bhqthebvswpzxeesjidsqpmmwovu/Build/Products/Release-iphonesimulator/SMCoreLib/SMCoreLib.framework/Headers/SMCoreLib-Swift.h:103:9: error: 'SMCoreLib/SMCoreLib.h' file not found
- NOTE  | [iOS] xcodebuild:  <unknown>:0: error: could not build Objective-C module 'SMCoreLib'

问题似乎出在自动生成的SMCoreLib-Swift.h生成的接口头文件中,找不到SMCoreLib.h总头文件。如果有任何建议,我将不胜感激。
1个回答

4
我有一个解决此问题的hack方法,但我希望有更好的方法。这个修复方法是将SMCoreLib.h文件放在:SMCoreLib/Classes/SMCoreLib.h。该文件只包含一行代码:
#import "SMCoreLib-umbrella.h"

问题似乎在于生成的接口头文件没有遵循模块映射中给定的总头文件名称更改。Cocoapods创建了这个模块映射和名称更改。此项目的Git存储库中存在这个hack修复程序:https://github.com/crspybits/SMCoreLib.git

真不敢相信这竟然有效。谢谢你!我也遇到了同样的问题。你找到了更好的解决办法吗? - Fernando Reynoso
这也解决了我的问题。我在其他任何在线资料中都没有找到过这方面的提及,所以我无法感谢你足够多! - James
你对这个回答的贡献实至名归,即使过去了7年,你依然值得获得一枚金牌。 - undefined

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