我正在构建一个cocoapod,它基本上包含一个依赖于这个框架的框架(私有源)和一个视图(开放源码),所有这些都是在目标C中创建的。
在podspec中,我有以下几行:
当使用use_frameworks!语法时,我不能使用#import MyFramework
我只是不明白发生了什么。
此外,当我移除spec.source_files行时,我可以使用#import MyFramework,它可以完美地工作,但当然不能使用MyView。
我做错什么了?
发布于 2020-01-16 23:22:38
对于今天遇到这个问题的人来说:这在CocoaPods中是一个已知的问题,在Github 这里和这里上提出了几个问题来讨论这个问题。
建议的解决方法是将您的podspec分为两部分:一个podspec只包含您的vendored_frameworks,另一个podspec只包含使用该框架的source_files。
Github上的用户crsantos有一个解决方法的贴身贴示例,我在下面复制了两个单独的podspecs。
分布式框架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源文件podspec请注意对分布式框架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发布于 2017-03-05 17:38:31
如果您使用use_frameworks!,您的pod本身将成为一个框架。因此,您应该使用#import MyPod而不是#import MyFramework,然后使用MyView。
还回顾一下public_header_files,以防您需要它。
发布于 2017-03-06 23:56:37
由于项目的荚现在是一个框架,您可以使用@importMyFramework.尝试将其作为模块导入
但是,如果这不起作用,那么尝试备份您的项目,然后运行pod deintegrate && pod install。而且,这个问题是非常相似的,它的一些评论和回答可能会有所帮助。
https://stackoverflow.com/questions/41139197
复制相似问题