React-native-firebase: Using RNFirebase in a Swift and Pods project

Created on 13 Mar 2018  路  5Comments  路  Source: invertase/react-native-firebase

I have a react-native project that is pod based. That means that React is imported as Pod and all dependencies are Pods as well. Also, the project using Swift so the Podfile declares use_frameworks!.

I created an example project here: https://github.com/guysegal/react-native-fireabase-problem

The project is standard - a combination of Swift & Objective C as development languages and Pods as dependency management.

When I import RNFirebase pod and try to compile I get this:

screen shot 2018-03-13 at 11 31 06

For some reason RNFirebase pod doesn't recongnize Firebase pods (specifically FirebaseAnalytics)

This prevents using react-native-firebase in a standard Swift and Pods project and I believe this should be addressed

Environment

iOS

Application Target Platform:
macOS Sierra

Development Operating System:
Xcode 9

React Native version:
0.52.2

RNFirebase Version:
3.2.7

iOS

All 5 comments

This issue might shine some light on the issue: https://github.com/invertase/react-native-firebase/issues/252

@IljaDaderko not exactly, I'm familiar with issue #252 - there was a problem with Firebase iOS SDK to compile when using CocoaPods and use_frameworks! but the issue is solved. If you go to the example project I mentioned and remove react-native-firebase dependency you'll see that the project compiles.

For some reason RNFirebase is having hard time to get to FirebaseAnalytics dependency. This is something I can't figure out why

Hi! My project is also through pods. I remember having that error too. I'll just share my pod file, maybe it will help.

platform :ios, '9.0'

target 'appname' do
  pod "yoga", :path => "../node_modules/react-native/ReactCommon/yoga"
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'BatchedBridge', # Required For React Native 0.45.0+
    'Core',
    # Add any other subspecs you want to use in your project
  ]

  # Required by RNFirebase
  pod 'Firebase/Core'
  pod 'RNFirebase', :path => '../node_modules/react-native-firebase/iOS'

  # [OPTIONAL PODS] - comment out pods for firebase products you won't be using.
  # pod 'Firebase/AdMob'
  pod 'Firebase/Analytics'
  pod 'Firebase/Auth'
  pod 'Firebase/Firestore'

  # For Crashlytics:
  pod 'Fabric', '~> 1.7.2'
  pod 'Crashlytics', '~> 3.9.3'

  # pod 'Firebase/Crash'
  # pod 'Firebase/Database'
  # pod 'Firebase/DynamicLinks'
  # pod 'Firebase/Messaging'
  # pod 'Firebase/RemoteConfig'
  # pod 'Firebase/Storage'

  pod 'GoogleMaps'

  pod 'RNBackgroundGeolocation', :path => '../node_modules/react-native-background-geolocation'

  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'

  pod 'RNBackgroundFetch', :path => '../node_modules/react-native-background-fetch'

  pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'

  pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'

end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "React"
      target.remove_from_project
    end
  end
end

I remember having to clean the project at some point as well.

@guysegal Sorry for the delayed response on this, I've only just got round to checking out your project. Unfortunately, due to a restriction in Cocoapods and how it works with dynamic frameworks, using RNFirebase as a pod in a swift project just won't work.

Instead you'll have to do the following:

1) Remove RNFirebase from your podfile
2) Run react-native link react-native-firebase from the root of your app

I have just tried this on your project and it compiles perfectly. Just note that when running react-native link react-native-firebase it will error as you don't have an android directory. This is nothing to worry about.

I'll get the v4 installation docs improved to include information about this.

@chrisbianca I too am facing a similar issue.
I'm using Cocoapods in a Native iOS Swift-based project, with _RNFirebase_ and _Firebase/Core_ both being installed as pods. I'm using React Native inside the project as a sub-module as my application is old and I wanted to leverage React Native's offerings in the app.

I tried your solution, of removing RNFirebase and running react-native link react-native-firebase , but the command throws error. (uploaded)
output

I know you would say that this command is gonna throw error because of the absence of android directory, which I need not worry about, but My app keeps crashing on the pages I've used React Native for UI.

Is there something I'm missing?
@guysegal Were you able to solve this?
P.S. Docs supposedly don't support my use case.

Was this page helpful?
0 / 5 - 0 ratings