iOS Dyanmic Framework with Firebase Dependencies
Asked Answered
V

1

2

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?

Volumeter answered 7/11, 2020 at 7:34 Comment(0)
A
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" => "[email protected]" }

  # ――― 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
Authorization answered 7/11, 2020 at 12:30 Comment(7)
it works for me, only thing, I never tried is to create a pod spec. Till now I directly add XCFramework in the Project Navigator panel. I have installed pods on the client-side as well but did not work. I thought it should work but it did not.But it works with your suggestion. Thanks for the help.Volumeter
@EDUsla As a new update in firebase, it won't allow configuring two different Targets separately(In my case host app and our SDK). They suggest converting it into a static library which directly has firebase frameworks added in project navigator pannel(not in the pods), but the issue repeats now. I am having error like No Such Module found. Any suggestions?Volumeter
@BhavinVaghela Unfortunately no, although I'm intrigued with the new update, I'll update the answer if we also encounter with this (and can solve that).Authorization
@Authorization How do you create xcframework? is it a xcworkspace project with pods dependencies?Consignee
@KonradSiemczyk Exactly, the same dependencies are in the Podfile of that workspace as well. Nothing extra in xcframework creation, we archive twice and combine them.Authorization
@Authorization is it possible to link manually with this approach or do the apps consuming the framework have to use cocoapods?Noelyn
@Noelyn since we are not including the dependencies into the .xcframework directly, any consumer must use CocoaPods to make this work as-is.Authorization

© 2022 - 2024 — McMap. All rights reserved.