iOS Dyanmic Framework with Firebase Dependencies

柔情痞子 提交于 2021-02-05 08:17:06

问题


We are developing a framework that is dependent on some firebase dependencies like login, analytics, etc. Once our framework is developed we will distribute it to our customers.

Things to be taken care of are

  1. Code should not be visible(Best suggestion is to create XCFramework)
  2. If possible create a dynamic framework instead of a static framework
  3. Can be distributed via Swift package manager or cocoapods

What we have tried

  1. We have tried to create a dynamic framework using pods and then create a XCFramework. But while importing into client app, pods module are not found
  2. We created static library and add firebase manually(In project directly) instead of pods, in that case XCFramework is not imported

We have tried to create XCFrame Work as mentioned here (for dynamic framework) XCFramework with Pods Dependencies

To hide code umbrella framework and universal library can be used,but with firebase, this approach is to typical and also not suggested on the internet at many places Is there any other/alternative way where we can fulfill our requirements?


回答1:


We have the exact same setup right now, and it works quite well. Hope that'll also be of help for you.

Things that are taken care of:

  • It's an XCFramework distribution.
  • It's been distributed by CocoaPods (albeit in a private Podspec repository)
  • It's a dynamic framework.

Prerequisites:

  • CocoaPods version >= 1.10.1
  • Xcode version >= 11.6 (could be lower though, not sure)

After creating your .xcframework, you need to have a .podspec for your framework, which should look like:

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

Then, we are consuming it in another project via Podfile, that will look like:

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

Then, that's it! When running pod install, you should see:

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: We also had to add a post_install setup in our Podfile, otherwise it'll not properly link the dependency frameworks:

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


来源:https://stackoverflow.com/questions/64725471/ios-dyanmic-framework-with-firebase-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!