【问题标题】:Create podspec to ship static library创建 podspec 以发布静态库
【发布时间】:2014-01-02 17:45:45
【问题描述】:

我正在尝试通过 cocoapods 发布一个静态库。我得到了没有任何构建方向的库,现在它可以放入我的 iOS 应用程序中。我不需要为使用它的每个应用程序构建库,而只需下载 lib 文件并包含头文件。有没有办法用 podspec 文件做到这一点?

这是我目前所拥有的:

Pod::Spec.new do |s|
  s.name         = "RTMPLib Library"
  s.version      = "1.0.0"
  s.summary      = "RTMPLib Library"
  s.homepage     = "https://github.com/jumper/RTMPLib.git"
  s.license      = { :type => 'MIT', :file => 'LICENSE' }
  s.author       = { "jon morehouse" => "jon@jumperapp.com" }
  s.source       = { :git => "https://github.com/jumper/RTMPLib.git", :tag => "#{s.version}" }
  s.platform     = :ios, '7.0'

  # arc components
  s.requires_arc = false
  s.preserve_paths = 'inc/rtmplib/*.h'
  s.vendored_libraries = 'lib/rtmplib.a'
  s.libraries = 'rtmplib'
  s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/#{s.name}/inc/rtmplib/**'}
  s.preserve_paths = 'L.framework'
end

实际的代码结构可以在这里找到:Git Repo

【问题讨论】:

标签: ios objective-c static-libraries cocoapods .a


【解决方案1】:

当然可以,而且很简单。您的 podspec 看起来是正确的。

我认为你应该创建一个 *.framework 并将你的库和头文件放在里面,这样更容易管理。这是一个框架的示例 podspec:

Pod::Spec.new do |s|
  s.name             = "LibName"
  s.version          = "0.2.0"
  s.summary          = "MySummary"

  s.homepage         = "http://myWebpPage.com/"

  s.license          = 'MIT'
  s.author           = { "Author" => "http://author.com/" }
  s.source           = { :git => "https://github.com/<GITHUB_USERNAME>/Project.git", :tag => s.version.to_s }

  s.platform     = :ios, '7.0'
  s.requires_arc = true
  s.ios.vendored_frameworks = 'StaticLibraryFolder/StaticLibrary.framework'
  s.frameworks = 'CoreData' , 'SystemConfiguration', 'CoreLocation'
  s.weak_framework = 'UIKit'

end

如果您不想使用 *.framework 文件,而是使用 *.a 和 *.h 文件,here's 就是一个例子。

【讨论】:

  • 我不知道你在说什么,这对我来说根本没有意义。请阅读 Apple 系统中的“*.framework”扩展 - 它基本上是一个文件夹,这怎么会使管理变得更加困难?对未来的建议:当你认为某人错了时,不要屈尊俯就并试图通过笑来侮辱他们。也许尝试进行民间讨论?特别是它可能会证明你是错的。祝你有美好的一天,在 Stackoverflow 上欢声笑语!
  • 使用 s.ios.vendored_frameworks 有助于通过 cocopods 发布静态库。是否有可能将其视为动态库?
  • 我创建了包含静态库和标头的框架,然后是 pod lib lint spec ,它显示未找到框架错误?
【解决方案2】:

我认为你需要这样做demo

 Pod::Spec.new do |s|
 s.name         = "RTMPLib Library"
 s.version      = "1.0.0"
 s.summary      = "RTMPLib Library"
 s.homepage     = "https://github.com/jumper/RTMPLib.git"
 s.license      = { :type => 'MIT', :file => 'LICENSE' }
 s.author       = { "jon morehouse" => "jon@jumperapp.com" }
 s.source       = { :git => "https://github.com/jumper/RTMPLib.git", :tag => "#{s.version}" }
 s.platform     = :ios, '7.0'

 # arc components
 s.requires_arc = false
# you static library`s .h file
 s.source_files = 'lib/*.h'
 s.vendored_libraries = 'lib/rtmplib.a'

end

【讨论】:

    猜你喜欢
    • 2013-10-29
    • 1970-01-01
    • 2020-06-16
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    • 1970-01-01
    相关资源
    最近更新 更多