简体   繁体   中英

Building a Cocoapod with both Swift and Objective-C: How to Deal with Umbrella Header Issues?

I have an existing Xcode framework, that uses both Swift and Objective-C, that I'm trying to get working as a Cocoapod. My steps so far are:

1) I used pod lib create SMCoreLib to initialize a new folder ( https://guides.cocoapods.org/making/using-pod-lib-create.html ).

2) I copied the Swift and Objective-C code from my framework into the SMCoreLib/Classes folder in this newly initialized pod folder. I also dragged this code into the relevant group in _Pods.xcodeproj.

3) I made some changes to the .podspec file for my project. It's as follows (note that the Github repo hasn't been updated yet with these changes; I can do that if someone wants):

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

My problem is that I get failures both trying to build the Example Xcode project and trying to lint the pod. Building the Example Xcode project, I get the following errors:

Xcode错误

From the command line, when I do:

pod lib lint --allow-warnings --verbose --no-clean

I get the following errors:

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

The problem appears to be that in the automatically generated SMCoreLib-Swift.h Generated Interface Header, the SMCoreLib.h umbrella header cannot be found. I would greatly appreciate any suggestions.

I have a hack fix for this problem. I'd like a better one. The fix is to put a SMCoreLib.h file at: SMCoreLib/Classes/SMCoreLib.h . The file contains the single line:

#import "SMCoreLib-umbrella.h"

The problem seems to be that the Generated Interface Header doesn't respect a name change for the umbrella header given in a module map. Cocoapods creates this module map and the name change. This hack fix is present in the Git repo for this project https://github.com/crspybits/SMCoreLib.git .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM