具有Firebase依赖关系的iOS Dyanmic框架

时间:2020-11-07 07:34:25

标签: ios swift xcode firebase xcframework

我们正在开发一个框架,该框架依赖于诸如登录,分析等一些Firebase依赖性。一旦我们的框架开发完毕,我们就会将其分发给我们的客户。

需要注意的事情

  1. 代码不应该可见(最好的建议是创建XCFramework)
  2. 如果可能,请创建动态框架而不是静态框架
  3. 可以通过Swift软件包管理器或cocoapods分发

我们尝试过的事情

  1. 我们尝试使用pod创建动态框架,然后创建XCFramework。但是在导入客户端应用程序时,未找到pods模块
  2. 我们创建了静态库,并手动(直接在项目中)添加了Firebase而不是pod,在这种情况下,不会导入XCFramework

我们已经尝试创建此处提到的XCFrame Work(用于动态框架) XCFramework with Pods Dependencies

可以使用隐藏的代码伞框架和通用库,但使用firebase时,这种方法是典型的,很多地方也不建议在Internet上使用 还有其他/替代方式可以满足我们的要求吗?

1 个答案:

答案 0 :(得分:1)

我们现在具有完全相同的设置,并且效果很好。希望对您也有帮助。

需要照顾的事情:

  • 这是XCFramework发行版。
  • 它已由CocoaPods分发(尽管在私有Podspec存储库中)
  • 这是一个动态框架。

先决条件:

  • CocoaPods版本> = 1.10.1
  • Xcode版本> = 11.6(虽然可能更低,但不确定)

创建.xcframework后,您需要为框架添加一个.podspec,该外观应类似于:

Pod::Spec.new do |s|

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  s.name         = "MyAwesomeSDK"
  s.version      = "1.0.0"
  s.summary      = "Best framework ever: MyAwesomeSDK"
  s.description  = <<-DESC
                   "Best framework ever: MyAwesomeSDK"
                   DESC
  s.homepage     = "http://github.com"
  s.license      = "MIT"
  s.author       = { "ItIsI" => "me@myself.com" }

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  s.platform = :ios
  s.ios.deployment_target = '11.3'

  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  s.source = { :http => '<MyAwesomeSDK.zip> (We're storing our zipped .xcframework in a hosted page)' }
  s.vendored_frameworks = 'MyAwesomeSDK.xcframework'

  s.swift_version = "5.0"

  # ――― Dependencies ―――――――――――――――――――――――――――---――――――――――――――――――――――――――――――― #
  s.dependency 'SwiftProtobuf',   '1.12.0'
  s.dependency 'lottie-ios',      '3.1.8'
  # Any other dependency you might need.
end

然后,我们通过Podfile在另一个项目中使用它,如下所示:

platform :ios, '13.0'

# If you're going to have a private Podspec repo, add the source URL here.
# Don't forget to add the original source if you're going to specify another source.
# source 'https://cdn.cocoapods.org/'

target 'Test' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # If you are publishing the SDK publicly or in a private Podspec repository, this is it:
  pod 'MyAwesomeSDK'

  # If not, you should provide the .podspec to your customers, and:
  pod 'MyAwesomeSDK', :podspec => '<path/to/MyAwesomeSDK.podspec>'

  target 'TestTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'TestUITests' do
    # Pods for testing
  end

end

然后就这样!运行pod install时,您应该看到:

Analyzing dependencies
Downloading dependencies
Installing MyAwesomeSDK (1.0.0)
# These are our own:
# ---
Installing SwiftProtobuf (1.12.0)
Installing lottie-ios (3.1.8)
# ---
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 3 total pods installed.

P.S:我们还必须在Podfile中添加post_install设置,否则将无法正确链接依赖项框架:

if ["SwiftProtobuf", "lottie-ios"].include? target.name
  target.build_configurations.each do |config|
    config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
  end
end