简体   繁体   中英

Cocoapods - Swift framework with internal static library dependency

I'm implementing an iOS framework written on Swift. This framework has an internal dependency on a C based static library. To make it work and based on some tutorials I've made a module map similar to this:

framework module Module {
    umbrella header "Module.h"

    explicit module ModuleDep {
        private header "header1.h"
    }

    export *
}

Based on that I can include C code in Swift like this:

import Module.ModuleDep

When export framework manually everything seems to work just fine. It is a sure thing, I want to have Cocoapods support for my framework with code visibility (easier to debug). The podspec, that make it work was this (some parts are omitted):

Pod::Spec.new do |s|
  s.platform = :ios
  s.ios.deployment_target = '12.0'

  s.module_map = "Module.modulemap"
  s.source_files = "Module/*.{h,swift}", "ModuleDep/*.h"
  s.vendored_libraries  = "ModuleDep/*.a"

  s.swift_version = "5.1"
end

From my understanding, vendored_libraries is used when this is the artifact you are providing to your users and that is why I don't like this solution.

I've also tried this spec variant:

Pod::Spec.new do |s|
  s.platform = :ios
  s.ios.deployment_target = '12.0'

  s.module_map = "Module.modulemap"
  s.source_files = "Module/*.{h,swift}", "ModuleDep/*.h", "ModuleDep/*.a"  
  s.swift_version = "5.1"
end

but it doesn't compile.

So what is the correct way to do this? Or what have I done wrong?

Since you are using a static library as a dependency then you must specify it as a library in your podspec file. Which is why your second approach is not working because it's a library not a source file.

As mentioned in the docs vendored_libraries are for libraries that come shipped with the Pod. Also in your case that C based static library is a dependency which must be shipped with the Pod. Thus using vendored_libraries should be ok in your case.

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