简体   繁体   English

Cocoapods - 具有内部静态库依赖项的 Swift 框架

[英]Cocoapods - Swift framework with internal static library dependency

I'm implementing an iOS framework written on Swift.我正在实现一个用 Swift 编写的 iOS 框架。 This framework has an internal dependency on a C based static library.该框架内部依赖于基于 C 的静态库。 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:基于此,我可以像这样在 Swift 中包含 C 代码:

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).这是肯定的,我希望 Cocoapods 支持我的具有代码可见性的框架(更易于调试)。 The podspec, that make it work was this (some parts are omitted):使其工作的 podspec 是这样的(省略了某些部分):

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.根据我的理解,当这是您提供给用户的工件时会使用vendored_libraries ,这就是我不喜欢此解决方案的原因。

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.由于您使用静态库作为依赖项,因此您必须在 podspec 文件中将其指定为库。 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.正如文档中提到的vendored_libraries用于 Pod 附带的库。 Also in your case that C based static library is a dependency which must be shipped with the Pod.同样在您的情况下,基于 C 的静态库是必须与 Pod 一起提供的依赖项。 Thus using vendored_libraries should be ok in your case.因此,在您的情况下使用vendored_libraries应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM