首页 > 解决方案 > CocoaPods 多个模块在一个 Pod 中,一个用于静态库,一个用于 swift

问题描述

我正在为 iOS 创建一个 Pod,它在后台使用 OpenSSL 提供加密 API。

到目前为止,我已经设法从 Swift 调用 OpenSSL,但似乎 Swift API 和 OpenSSL API 混合在一起,生活在同一个OpenSSL模块中。

是否可以OpenSSL为 C OpenSSL API 创建模块和OpenSSLTest2为 Swift API 创建模块?另外,如果可能的话,我希望OpenSSL模块是私有的。

这是我的 podspec。

Pod::Spec.new do |s|
  s.name             = 'OpenSSLTest2'
  s.version          = '0.1.0'
  s.summary          = 'A short description of OpenSSLTest2.'
  s.description      = <<-DESC
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'https://github.com/yshrsmz/OpenSSLTest2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'yshrsmz' => 'mymailaddress' }
  s.source           = { :git => 'https://github.com/yshrsmz/OpenSSLTest2.git', :tag => s.version.to_s }

  s.swift_version = '4.2'
  s.platform = :ios
  s.ios.deployment_target = '8.0'

  # if I change here to 'OpenSSLTest' or something, it won't compile 
  s.module_name = 'OpenSSL'
  s.source_files = 'OpenSSLTest2/Classes/**/*.swift', 'OpenSSLTest2/OpenSSL/include/**/*.h'
  s.header_dir = 'openssl'
  s.public_header_files = 'OpenSSLTest2/OpenSSL/include/openssl/*.h'
  s.preserve_paths = 'OpenSSLTest2/Classes/OpenSSL/module.modulemap'
  s.libraries = 'crypto', 'ssl'
  s.vendored_libraries = 'OpenSSLTest2/OpenSSL/lib/libcrypto.a', 'OpenSSLTest2/OpenSSL/lib/libssl.a'

  s.pod_target_xcconfig = {
      'SWIFT_INCLUDE_PATHS' => '$(PODS_ROOT)/OpenSSLTest2/OpenSSL/module $(PODS_TARGET_SRCROOT)/OpenSSL/module',
      'LIBRARY_SEARCH_PATHS' => '$(PODS_ROOT)/OpenSSLTest2/OpenSSL/lib'
  }
end

这是 OpenSSL 的模块图。

module OpenSSL [system] {
    header "openssl/conf.h"
    header "openssl/evp.h"
    header "openssl/err.h"
    header "openssl/bio.h"
    header "openssl/ssl.h"
    header "openssl/md4.h"
    header "openssl/md5.h"
    header "openssl/sha.h"
    header "openssl/hmac.h"
    header "openssl/rand.h"
    header "openssl/ripemd.h"
    header "openssl/pkcs12.h"
    header "openssl/x509v3.h"

    export *
}

这也是完整的存储库。

https://github.com/yshrsmz/OpenSSLTest2/tree/0.1.0-pre

谢谢。

标签: iosswiftopensslcocoapodspodspec

解决方案


我最终创建了一个仅包含 OpenSSL(带有模块映射)的框架,然后将该框架用作vendored_frameworks


推荐阅读