Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Firebase in dynamic Swift framework (with/without Cocoapods) and import framework into app target

Tags:

Firebase for iOS is an Objective-C framework which recommends integration using Cocoapods. Here's how I'm trying to set it up:

I am running Xcode 8b6 on OS X 10.11.6. The app is being built with the iOS 10 SDK, targeting iOS 9.

MyApp is the regular (Swift) iOS app I want to use.

MyFramework is an embedded dynamic framework with the app, q. I would like all the Firebase code to be abstracted away into the framework, and therefore add Firebase to the MyFramework target in my Podfile:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

target 'MyApp' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

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

target 'MyApp' do
  pod 'Firebase'
  pod 'Firebase/Database'
  pod 'Firebase/Auth'
end

On running pod install, I am able to import Firebase in all .swift files in MyFramework. However, on using import MyFramework anywhere in my app, I get the error Missing required module Firebase.

Thinking this could be a Cocoapods issue, I started a fresh project and integrated Firebase manually, but ended up with the same issue. Is this a known issue? If so, are there any fixes for it?

like image 340
caughtinflux Avatar asked Aug 18 '16 02:08

caughtinflux


People also ask

Do you need CocoaPods for Firebase?

CocoaPods is not required for Swift Package Manager users. For Firebase versions 8 and higher, Swift Package Manager is the recommended installation method.

How do I add Firebase to Apple app?

Go to the Firebase console. In the center of the project overview page, click the iOS+ icon to launch the setup workflow. If you've already added an app to your Firebase project, click Add app to display the platform options. Enter your app's bundle ID in the bundle ID field.

What is Firebase in iOS Swift?

Firebase is a mobile backend-as-a-service that provides powerful features for building mobile apps. Firebase has three core services: Realtime database. User authentication. Hosting.


1 Answers

In the podspec of MyFramework, add dependency of the Firebase pods. Also set the static framework flag as true. This is how your podspec should look:

*OTHER METADATA RELATED TO MYFRAMEWORK*
s.static_framework = true
s.dependency   'Firebase'
s.dependency   'Firebase/Database'
s.dependency   'Firebase/Auth'`
like image 50
PoojaChow Avatar answered Oct 14 '22 01:10

PoojaChow