invertase / react-native-firebase

๐Ÿ”ฅ A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.48k stars 2.18k forks source link

[๐Ÿ›] The following Swift pods cannot yet be integrated as static libraries [has workaround / Need Expo instructions to close this] #6332

Closed RodolfoGS closed 1 year ago

RodolfoGS commented 1 year ago

[UPDATE: we have something that works below, but we need an Expo user to figure out how to correctly set two items in the Podfile in The Expo Way]

Issue

pod install not working with the following error:

[!] The following Swift pods cannot yet be integrated as static libraries:

The Swift pod `FirebaseCoreInternal` depends upon `GoogleUtilities`, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.

How to reproduce

  1. expo init Test --npm
  2. Select "Bare workflow -> minimal"
  3. cd Test
  4. npm i @react-native-firebase/analytics @react-native-firebase/app
  5. cd ios
  6. pod install
  7. Error appears

If your prefer I created a repo: https://github.com/RodolfoGS/FirebaseCoreInternal-issue

  1. git clone git@github.com:RodolfoGS/FirebaseCoreInternal-issue.git
  2. cd FirebaseCoreInternal-issue/
  3. npm i
  4. cd ios
  5. pod install
  6. Error happens

This happens with all Firebase dependences, I tested with:


Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "test", "version": "1.0.0", "main": "index.js", "scripts": { "start": "expo start --dev-client", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web" }, "dependencies": { "@react-native-firebase/analytics": "^15.0.0", "@react-native-firebase/app": "^15.0.0", "expo": "~45.0.0", "expo-splash-screen": "~0.15.1", "expo-status-bar": "~1.3.0", "react": "17.0.2", "react-dom": "17.0.2", "react-native": "0.68.2", "react-native-web": "0.17.7" }, "devDependencies": { "@babel/core": "^7.12.9" }, "private": true } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` OUTPUT GOES HERE ``` - **Platform that you're experiencing the issue on**: - [x] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `15.0.0` - **`Firebase` module(s) you're using that has the issue:** - `@react-native-firebase/analytics` - **Are you using `TypeScript`?** - `Y/N` & `VERSION`


mikehardy commented 1 year ago

(re-posting/moving here, from #6323)

@RodolfoGS thanks posting a repro!

What happens if you affect this:

https://github.com/RodolfoGS/FirebaseCoreInternal-issue/blob/4c626b5cdcac40ec99a1c2b3fead2ae5db61670e/ios/Podfile#L16

Experiments to run:

1- make that line say nothing except use_frameworks! (that is: no linkage stuff after) 2- make that line say use_frameworks! :linkage => :dynamic (note! This should be same result as experiment 1, dynamic is the default) 3- make that line say use_frameworks! :linkage => :static

I'm not sure how exactly you would configure that in Podfile.properties.json so that you are doing it The Expo Way but based on the results of the experiments above we may have a working solution for cocoapods, then (assuming we find one that works) we can back that in to Podfile.properties.json

Note that use_frameworks interacts with Hermes and Flipper and react-native 0.69 with varying degrees of success depending on static or dynamic linkage. See https://github.com/reactwg/react-native-releases/discussions/21#discussioncomment-2924919 In general you should disable hermes and flipper if you use use_frameworks right now, and you should be on react-native 0.68.2 or lower, 0.69.0 won't work. (0.69.1 will have hermes and 0.69.1 working, but flipper will still not work pending a PR in the area...See https://github.com/reactwg/react-native-releases/discussions/23#discussioncomment-3012014)

RodolfoGS commented 1 year ago

Results:

  1. pod install works in demo repo without another library installed, but failed if you install another library, like react-native-google-mobile-ads with the following error:
    [!] The 'Pods-Test' target has transitive dependencies that include statically linked binaries: (__path__/Test/ios/Pods/Google-Mobile-Ads-SDK/Frameworks/GoogleMobileAdsFramework-Current/GoogleMobileAds.xcframework and __path__/Test/ios/Pods/GoogleUserMessagingPlatform/Frameworks/Release/UserMessagingPlatform.xcframework)
  2. Same result as 1
  3. Same as 1
mikehardy commented 1 year ago

So that actually seems like 1 will work for react-native-firebase, I think that's a positive result and figuring out how to preserve that result while using the default Expo podfile and making it happen with Podfile.properties.json would be useful as a follow-up.

But now we move back to the other repo (mobile ads) to see what's going on there. I wonder if you reached in to node_modules/react-native-google-mobile-ads/ and tweaked the .podspec file here:

https://github.com/invertase/react-native-google-mobile-ads/blob/5d2048b530b798740c9fed392772568f909dd6b2/RNGoogleMobileAds.podspec#L43-L48

By setting $RNGoogleMobileAdsAsStaticFramework = true in your Podfile if that would let it work :thinking: - that was the solution for react-native-firebase and it appears to be implemented but just not documented in react-native-google-mobile-ads

mikehardy commented 1 year ago

@RodolfoGS $RNGoogleMobileAdsAsStaticFramework = true in the Podfile then reinstalling pods was the key for me. I reproduce your error when I do not have that set to true, and I build react-native-firebase + react-native-google-mobile-ads (with podspec patch to Google-Mobile-Ads-SDK 9.6.0!) with it.

I don't have time to play with Expo right now, but for Expo people on react-native-firebase:

1- need to determine what to put in Podfile.properties.json so it correctly sets use_frameworks! :linkage => :dynamic

Google Ads needs the Podfile variable set for static builds then it should all work

RodolfoGS commented 1 year ago

I tested that and react-native-mobile-ads could be installed now with the combination of:

But I have problems with another libraries, maybe because they doesn't have the "$RNGoogleMobileAdsAsStaticFramework" hack.

The two libraries that I have the same problem are:

But I think that another users could have more issues with another libraries.

In the meanwhile I will stay in 14.11.1

mikehardy commented 1 year ago

Interesting, you could check their podspec and try to patch it, that variable that we add does a really simple change and it is patch-patchable really trivially as a test...

mikehardy commented 1 year ago

The specific change in the affected libraries is just to add this:

s.static_framework = true

(the s. is a variable in the ruby block, it may be called something different but it is hopefully obvious whatever it is)

lockieluke commented 1 year ago

how do i fix this? which version should i downgrade to

mikehardy commented 1 year ago

@lockieluke You don't specify what the "this" is. There are a few problems depending on whether what you want is "to use react-native new architecture", or "I want to use hermes on iOS" or "I'm on Expo" or any of a number of things. The comments above contain a lot of detail. You can help work the problem and most likely use react-native-firebase v15 with the changes detailed above

Or you can stay on react-native-firebase v14.whatever-is-current and it may work for you, depending on what "this" is in

how do i fix this?

https://stackoverflow.com/help/how-to-ask

lockieluke commented 1 year ago

it fails to build if i use the latest version of react-native-firebase

mikehardy commented 1 year ago

That is still a vastly incomplete description of the problem. What version of react-native are you on? Do you use Expo? Do you also use react-native-google-mobile-ads? Do you use Hermes?

Given two comments unable to completely specify your problem, thus my inability to help really, I'm going to suggest staying with v14 is probably best

nbonatsakis commented 1 year ago

Does anyone know if there is a way to resolve this under the managed workflow using EAS?

mikehardy commented 1 year ago

@nbonatsakis I'm not sure how to do it in Expo terms but if you can:

1) determine what to put in Podfile.properties.json so it correctly sets use_frameworks! :linkage => :dynamic

and

2) figure out how to set $RNFirebaseAsStaticFramework = true

and

3) set this variable for react-native-google-mobile-ads if you use that:

$RNGoogleMobileAdsAsStaticFramework = true

...and there are no other native libraries to patch then... should work? It's relatively easy to do that in a non-Expo context but I don't have Expo experience so I'm not sure

Otherwise, v14 here is already aging but it was state of the art just a month ago or so, open source is messy and compatibility is difficult but if you can't answer the "how" for 1 and 2 above, someone surely will before too long (I hope!)

nbonatsakis commented 1 year ago

Hmm. I pre-built the project and changed the Podfile to include use_modular_headers! and that seemed to work. I was going to write a quick EAS config plugin to do this modification, any concerns about fixing it that way? (fewer steps).

mikehardy commented 1 year ago

I'm a very practical person with a strict requirement for automated solutions. If you can automate something that works 100% of the time every time, that works for me and we'll all do a happy dance!

mikehardy commented 1 year ago

Users have noted, when trying use_frameworks! and react-native 0.69.1 that builds to real devices will fail because the patches in 0.69.1 are incompatible with bitcode. Xcode 14 will deprecate bitcode, so simply disabling it appears to a reasonable solution, then react-native 0.69.1 is accessible in combo with the Podfile variables above

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
ahnafnafee commented 1 year ago

Temporary Workaround: This might be an issue with one of the new versions that was shipped. I was encountering the same error in 15.1.1 (was saying FirebaseCore instead of FirebaseCoreInternal for me) and once I downgraded to 14.11.0, the ios build started working without any issues.

harterc1 commented 1 year ago

This fixed it for me:

  1. Add expo-build-properties package

    expo add expo-build-properties
  2. Update app.json to include:

{
  "expo": {
    "plugins": [
      [
        "expo-build-properties",
        {
          "ios": {
            "useFrameworks": "static"
          }
        }
      ]
    ]
  }
}
tux2nicolae commented 1 year ago

Users have noted, when trying use_frameworks! and react-native 0.69.1 that builds to real devices will fail because the patches in 0.69.1 are incompatible with bitcode. Xcode 14 will deprecate bitcode, so simply disabling it appears to a reasonable solution, then react-native 0.69.1 is accessible in combo with the Podfile variables above

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end

mikehardy I have the same issue with bitecode but when i'll use your solution I get another error Undefined symbol: _OBJC_CLASS_$_FIRAnalytics

mikehardy commented 1 year ago

With apologies I'm traveling right now so haven't had time to do another batch of resolution / developer-experience-smoothing here, or in the related repo where I test things (discussion at https://github.com/mikehardy/rnfbdemo/issues/10)

mahdieh-dev commented 1 year ago

This might be an issue with one of the new versions that was shipped. I was encountering the same error in 15.1.1 (was saying FirebaseCore instead of FirebaseCoreInternal for me) and once I downgraded to 14.11.0, the ios build started working without any issues.

This works ๐Ÿ‘

mikehardy commented 1 year ago

Downgrading of course works, but that's the same as saying "the new version is a bit difficult so not using it avoids the difficulty", in other words it is a tautology --> 1 = 1. For anyone that needs to do this I do understand, but please pay attention to this issue for progress so you can successfully move on to future version versus being stuck forever on the old stuff

bombillazo commented 1 year ago

@harterc1 Thanks for this!

Also needed to add this to the podfile manually to make it work (source):

installer.pods_project.targets.each do |target|
  if target.name == 'RCT-Folly'
    target.build_configurations.each do |config|
      config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) ${PODS_ROOT}/fmt/include"
    end
  end
end

I have to figure away to add this to the podfile via expo/eas to make the build process work.

 Compiling expo-dev-menu Pods/expo-dev-menu ยป EventHandlerRegistry.cpp
โ€บ Compiling expo-dev-menu Pods/expo-dev-menu ยป EXDevMenuAppInfo.m

โŒ  (../../node_modules/expo-dev-menu/ios/EXDevMenuAppInfo.m:3:9)

  1 | // Copyright 2015-present 650 Industries. All rights reserved.
  2 | #import "EXDevMenuAppInfo.h"
> 3 | #import <EXDevMenu-Swift.h>
    |         ^ 'EXDevMenu-Swift.h' file not found
  4 | #import <EXManifests/EXManifestsManifestFactory.h>
  5 | 
  6 | @implementation EXDevMenuAppInfo
dimaportenko commented 1 year ago

I'm able to install pods with

pod 'GoogleUtilities', :modular_headers => true

but I'm getting error when I'm trying to build app

CleanShot 2022-07-12 at 15 21 20@2x
Khachik98 commented 1 year ago

You may not need to use use_frameworks! or use_modular_headers! because it's getting conflict with use_flipper

You can add the following without using them:

pod 'Firebase', :modular_headers => true pod 'FirebaseCoreInternal', :modular_headers => true pod 'GoogleUtilities', :modular_headers => true

....add any library need headers

Don't say thank you

LeandroTamola commented 1 year ago

I was not able to run a project using React Native 0.69.1 and firebase 15.1.1 on an M1 Mac. I tried to follow the docs and also most of the recommendations here, but I had no luck.

Anyone with a successful experience?

mikehardy commented 1 year ago

I'm travelling and have not had a chance to move my demo forward from 0.69.0 but my make demo script (should have a link above?) Definitely worked on M1. It will need an update for 0.69.1, I'll get it as soon as I can, until then I'd look at exactly what it is doing and stay on 0.69.0 for now with the patch-package patch it uses

marf commented 1 year ago

Any chance to make it work without use_frameworks! ? Using it gives conflicts with some libraries like react-native-reanimated

DevJett commented 1 year ago

I fixed the issue, I disabled use_frameworks and just put the following

     pod 'Firebase', :modular_headers => true
     pod 'FirebaseCore', :modular_headers => true
     pod 'GoogleUtilities', :modular_headers => true
     $RNFirebaseAsStaticFramework = true

And keep using flipper

  use_flipper!()

I tested it on both test and real devices and it works great ๐ŸŽ‰

What do you think of my solution?

See full answer here if you wanted to use rich content notification.

dimaportenko commented 1 year ago

@Shrroy are you using @react-native-firebase/messaging?

rochapablo commented 1 year ago

@Shrroy can you share your Podfile?

coprocoder commented 1 year ago

@Shrroy can you share your Podfile?

Just in case, I'll attach the full code so that it works for you. I marked the blocks that solved the problem.

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false

# ==> added: Begin 
# Override Firebase SDK Version
$FirebaseSDKVersion = '9.2.0'
$RNFirebaseAsStaticFramework = true
# ==> added: End 

target 'YourAppName' do
  config = use_native_modules!
  flags = get_default_flags()

  # ==> added: Begin 
  pod 'Firebase', :modular_headers => true  
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  # ==> added: End 

  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'YourAppNameTests' do
    inherit! :complete
  end

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
  pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
  pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly"

  use_flipper!()

  post_install do |installer|
    flipper_post_install(installer)
    react_native_post_install(installer)
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.4'
      end
    end 

    # Change __IPHONE_OS_VERSION_MIN_REQUIRED from 10 to 14 in RCT-Folly source file Time.h
    `sed -i -e  $'s/__IPHONE_10_0/__IPHONE_14_0/' #{installer.sandbox.root}/RCT-Folly/folly/portability/Time.h`
    # Remove typedef line in RCT-Folly source file Time.h
    `sed -i -e  $'s/typedef uint8_t clockid_t;//' #{installer.sandbox.root}/RCT-Folly/folly/portability/Time.h` 

    `sed -i -e  $'s/atomic_notify_one(state)/folly::atomic_notify_one(state)/' #{installer.sandbox.root}/RCT-Folly/folly/synchronization/DistributedMutex-inl.h` 
    `sed -i -e  $'s/atomic_wait_until(&state, previous | data, deadline)/folly::atomic_wait_until(&state, previous | data, deadline)/' #{installer.sandbox.root}/RCT-Folly/folly/synchronization/DistributedMutex-inl.h` 
  end
end

Config

"react": "^18.1.0",
"react-native": "0.68.2",
"@react-native-firebase/app": "^15.0.0",
"@react-native-firebase/messaging": "^15.0.0",
rochapablo commented 1 year ago

@coprocoder thank you. Mine is working too, here's the Podfile

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'

target 'myapp' do  
  $RNFirebaseAnalyticsWithoutAdIdSupport = true  

  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true

  # To use Static Frameworks on iOS, you also need to manually enable this for the project with the following global to the top of your /ios/Podfile file:
  # https://rnfirebase.io/#altering-cocoapods-to-use-frameworks
  $RNFirebaseAsStaticFramework = true

  pod 'react-native-video', :path => '../node_modules/react-native-video/react-native-video.podspec'  

  config = use_native_modules!
  use_react_native!(:path => config["reactNativePath"])

  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency.podspec"

  # Enables Flipper.
  # Note that if you have use_frameworks! enabled, Flipper will not work and you should disable these next few lines.
  use_flipper!
  post_install do |installer|
    flipper_post_install(installer)
  end
end
"@react-native-firebase/analytics": "^15.1.1",
"@react-native-firebase/app": "^15.1.1",
"@react-native-firebase/crashlytics": "^15.1.1",
"@react-native-firebase/remote-config": "^15.1.1",
"react-native": "^0.64.2",
DevJett commented 1 year ago

@rochapablo @coprocoder @dimaportenko Yes, I'm using @react-native-firebase/messaging

And here is what my Podfile looks like

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false

target 'myApp' do
  config = use_native_modules!
  flags = get_default_flags()

  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  $RNFirebaseAsStaticFramework = true

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'myAppTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end
hayderespit commented 1 year ago

For React Native 0.69.1

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false

# ==> added: Begin 
$RNFirebaseAsStaticFramework = true
# ==> added: End 

target 'PlazaFood' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  # ==> added: Begin 
  pod 'Firebase', :modular_headers => true  
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  # ==> added: End 

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'PlazaFoodTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end
alexco2 commented 1 year ago

I also have this problem with expo managed workflow when I use expo prebuild --clean

Command `pod install` failed.
โ””โ”€ Cause: The following Swift pods cannot yet be integrated as static libraries:

The Swift pod `FirebaseCoreInternal` depends upon `GoogleUtilities`, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.

The Swift pod `FirebaseStorage` depends upon `FirebaseStorageInternal`, `FirebaseAppCheckInterop`, `FirebaseAuthInterop`, `FirebaseCore`, and `FirebaseCoreExtension`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.
coprocoder commented 1 year ago

@alexco2 Try this solution, and add your pod dependencies

  pod 'FirebaseCoreInternal', :modular_headers => true  
  pod 'FirebaseStorage', :modular_headers => true

also try adding all mentioned pods in the bug report

dimaportenko commented 1 year ago

@Shrroy thanks for sharing Podfile. I can confirm, that it solved my build issues.

alexco2 commented 1 year ago

@coprocoder thank you for the fast response. I'm new to expo since I have always been working with vanilla rn. Isn't the podfile generated automatically in an expo managed project? I assume if I change the podfile, it will just be overwritten on the next expo prebuild, wouldn't it?

coprocoder commented 1 year ago

@alexco2 In general terms, a Podfile is your code (or build config), and a Podfile.lock is a list of all dependencies (as packages.lock), Pods folder the same as node_modules, but for swift packages. When you add pods to a file, you specify them as a dependency. Yes, you can change the Podfile, the next time you install the pods, they will also be loaded / deleted, the pods folder and the Podfile.lock will be updated.

mrkpatchaa commented 1 year ago

I'm using RN 0.69.1 and I tried this solution, but now I'm getting this error

ios/Pods/Headers/Private/Firebase/Firebase.h:54:13: fatal error: 'FirebaseFunctions/FirebaseFunctions-Swift.h' file not found
    #import <FirebaseFunctions/FirebaseFunctions-Swift.h>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Same as in #6382

arthwood commented 1 year ago

As original message suggests, adding only:

pod 'GoogleUtilities', modular_headers: true

fixed the issue for me. (I still have use_flipper! but no use_modular_headers!)

Edit: at least pods installation worked well, but building app in xcode failed with:

Module FirebaseCore not found

changing to:

require "active_support/core_ext/object"

with_options modular_headers: true do
  pod 'GoogleUtilities'
  pod 'FirebaseCore'
end

made the build successful.

mikehardy commented 1 year ago

Interesting - I really appreciate everyone working together here to try things, seriously it is a huge help since I have very limited time at the moment, and for the next few weeks unfortunately. Nicely done.

Someone mentioned above about eliminating use_frameworks in the main Podfile but essentially bringing the sub-pods (those from firebase-ios-sdk) into the system as frameworks at the layer below the react-native-firebase Pods. This was something I wanted to try but didn't have time for yet, and I'm happy to hear it seems like this is a successful path

A PR for this to make it official seems like it would be:

Then things may work without use_frameworks! in the app Podfile, but while still using firebase-ios-sdk v9 which requires being used as a static framework ?

Our e2e testing framework is not too hard to work with if someone wants to try this - https://github.com/invertase/react-native-firebase/blob/main/tests/README.md

The command yarn tests:ios:pod:install and yarn tests:ios:build are the things you'll want to run to verify it works

mikehardy commented 1 year ago

I do have react-native 0.69.1 working on intel and m1 mac here now: https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh - still using the use_frameworks! style that I know is problematic, but at least demonstrating it working, with react-native 0.69.1 and current react-native-firebase.

(worth noting that hermes must be disabled, it does not work, even if you disable bitcode to get it to compile - this is not ideal but it is the reality at the moment, with use_frameworks! enabled)

aprilmintacpineda commented 1 year ago

I fixed the issue, I disabled use_frameworks and just put the following

     pod 'Firebase', :modular_headers => true
     pod 'FirebaseCore', :modular_headers => true
     pod 'GoogleUtilities', :modular_headers => true
     $RNFirebaseAsStaticFramework = true

And keep using flipper

  use_flipper!()

I tested it on both test and real devices and it works great ๐ŸŽ‰

What do you think of my solution?

See full answer here if you wanted to use rich content notification.

Just wanna say this worked for me, I tried the other solutions on this thread but I encountered different errors.

kvbalib commented 1 year ago

Regarding Expo managed, here's a config plugin that I've made, and works for me

const fs = require('fs');
const path = require('path');
const generateCode = require('@expo/config-plugins/build/utils/generateCode');
const configPlugins = require('@expo/config-plugins');

const code = `  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  $RNFirebaseAsStaticFramework = true`;

const withReactNativeFirebase = (config) => {
  return configPlugins.withDangerousMod(config, [
    'ios',
    async (config) => {
      const filePath = path.join(
        config.modRequest.platformProjectRoot,
        'Podfile'
      );
      const contents = fs.readFileSync(filePath, 'utf-8');

      const addCode = generateCode.mergeContents({
        tag: 'withReactNativeFirebase',
        src: contents,
        newSrc: code,
        anchor: /\s*get_default_flags\(\)/i,
        offset: 2,
        comment: '#',
      });

      if (!addCode.didMerge) {
        console.error(
          "ERROR: Cannot add withReactNativeFirebase to the project's ios/Podfile because it's malformed."
        );
        return config;
      }

      fs.writeFileSync(filePath, addCode.contents);

      return config;
    },
  ]);
};

module.exports = withReactNativeFirebase;
mikehardy commented 1 year ago

For those trying to integrate without 'use_frameworks!' it seems to work well with the exception of storage. Cocoapods appears to only generate a necessary header file for storage in the presence of the use_frameworks flag

otaviogaiao commented 1 year ago

@kvbalib many thanks! It works!

kesylo commented 1 year ago

@kvbalib many thanks! It works! But please can we have a definitive solution for this @mikehardy ?

mikehardy commented 1 year ago

@kvbalib many thanks! It works! But please can we have a definitive solution for this @mikehardy ?

A couple things, to make expectations really clear so no one is disappointed

1- use_frameworks! is required in your Podfile for the firebase-ios-sdk underlying this module. Full stop. You can try to hack around it, and have partial success, but it won't be officially supported and the modules that strictly require it will grow in number over time.

The real but currently unsatisfying solution to that is that react-native needs changes to make it seamless, including Flipper (needs helpers!), and Hermes (close to working), and new architecture for future (needs work from Meta employees). Also any 3rd party modules that are not compatible need you (yes you, no one else will do it for you...) To file an issue asking for status and offering to help

2- the Expo-specific solution will have to come from someo using Expo (so they can test it) and be made by them as a PR here. I don't use Expo. I have no Expo experience. I am not the person that's going to make an Expo PR. And I'm the only maintainer here ๐Ÿ˜…. So if this is important to you, please help by doing the PR and i will help by getting it merged and released

I hope this clearly lays out the path forward for an official supported solution , that's my goal here.

It's going to be a while until it's all easy out of the box while this happens, until then v14 of this module is always available...