使用'vend_框架'和'source_files'使用'use_frameworks'进行cocoapod'

Dri*_*ico 10 frameworks ios cocoapods swift

我正在构建一个基本上包含框架(私有源)和依赖于此框架的视图(开源)的cocoapod,所有这些都是在Objective-C中完成的.

在podspec中,我有以下几行:

  • spec.vendored_frameworks ='MyPod/Framework/MyFramework.framework'
  • spec.source_files = ['MyPod/UI/Views/MyView.{h,m}']

使用use_frameworks!语法时,我不能#import MyFramework

我只是不明白发生了什么.

此外,当我删除spec.source_files线,我可以#import MyFramework,它完美的工作,但当然我不能使用MyView.

我究竟做错了什么 ?

sho*_*ing 5

对于今天遇到此问题的任何人:这是 CocoaPods 中的一个已知问题,Github 上提出了一些问题,此处此处讨论了该问题。

建议的解决方法是将您的 podspec 分成两部分:一个 podspec 仅包含您的vendored_frameworks,另一个 podspec 仅包含source_files使用该框架的 podspec。

Github 上的用户 crsantos 已经发布了此解决方法的示例,其中包含我在下面复制的两个单独的 podspec。

供应框架 podspec:

# Regarding https://github.com/CocoaPods/CocoaPods/issues/6409
Pod::Spec.new do |s|
  s.name             = 'SampleDynamicLibPod'
  s.version          = '0.0.1'
  s.summary          = 'SampleDynamicLibPod. Cool Story bro!'

  s.description      = <<-DESC
Blah Blah Blah Blah Blah description
                       DESC

  s.homepage         = 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'Carlos Santos' => 'mail@example.com' }
  s.source           = { :git => 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource.git', :tag => "#{s.name}-#{s.version.to_s}" }
  # this is the way of tagging diferent podspecs on the same repo
  # Dont't forget to tag your repo with `SampleDynamicLibPod-0.0.1` for this specific spec

  s.module_name      = 'SampleDynamicLibPod'

  s.ios.deployment_target = '9.0'
  s.platform = :ios, '9.0'
  s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3' }

  s.vendored_frameworks = 'SampleDynamicLibPod/Frameworks/SampleDynamicLib.framework'
end
Run Code Online (Sandbox Code Playgroud)

源文件 podspec.h 请注意对供应商框架 podspec 的依赖性。

# Regarding https://github.com/CocoaPods/CocoaPods/issues/6409

Pod::Spec.new do |s|
  s.name             = 'WrapperAroundSampleDynamicLibPod'
  s.version          = '0.0.2' # just a different number to avoid confusion with the other podspec
  s.summary          = 'WrapperAroundSampleDynamicLibPod. Cool Story bro!'

  s.description      = <<-DESC
Wrapper Around Sample Dynamic Lib Pod Blah Blah Blah Blah Blah Blah Blah Blah
                       DESC

  s.homepage         = 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'Carlos Santos' => 'mail@example.com' }
  s.source           = { :git => 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource.git', :tag => "#{s.name}-#{s.version.to_s}" }

  # Dont't forget to tag your repo with `WrapperAroundSampleDynamicLibPod-0.0.2` for this specific spec

  s.module_name      = 'WrapperAroundSampleDynamicLibPod'

  s.ios.deployment_target = '9.0'
  s.platform = :ios, '9.0'
  s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3' }

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

  s.dependency 'CocoaLumberjack/Swift'
  s.dependency 'SampleDynamicLibPod', '0.0.1' # you can achieve this with "#{s.name}-#{s.version.to_s}" from the 
end
Run Code Online (Sandbox Code Playgroud)


小智 1

如果你使用use_frameworks!你的pod本身就会成为一个框架。因此您应该#import MyPod代替#import MyFramework然后使用MyView.

public_header_files如果您需要的话,也请查看。