13

I'm trying to ship a static library via cocoapods. I was given the library without any build directions right now its a drop in to my iOS app. I don't need to build the library for each application using it, rather just download the lib files and include the headers. Is there a way to do this with a podspec file?

Here's what I have thus far:

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

The actual code structure can be found here: Git Repo

JonMorehouse
  • 1,313
  • 6
  • 14
  • 34

2 Answers2

4

Sure it's possible, and it's easy. Your podspec looks correct.

I think you should create a *.framework and put your library and header files inside, so it's easier to manage. Here's an example podspec for a framework:

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

If you don't want to do it with a *.framework file, but with *.a and *.h files instead, here's an example.

michal.ciurus
  • 3,616
  • 17
  • 32
  • I have no idea what you're talking about, it doesn't make sense to me at all. Please read up on "*.framework" extension in the Apple system - it's basically a folder, how can that make anything harder to manage? An advice for the future: when you think someone's wrong, don't condescend and try to insult them by laughing. Maybe try a civil discussion? Especially that it might turn out that you're the one in the wrong. Have a nice day and many, many laughs here on Stackoverflow! – michal.ciurus May 24 '18 at 09:38
  • Is using `s.ios.vendored_frameworks` helps in shipping a static lib via cocopods. Is it possible that this will be treated as a dynamic library? – Manish Singh Nov 15 '19 at 23:41
  • I create framework contain static lib and header, then pod lib lint spec , it show framework not found error? – signal Dec 30 '21 at 09:20
2

I think you need do like that 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
张旭东
  • 21
  • 2