react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

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

Open RodolfoGS opened this issue 2 years ago โ€ข 63 comments

[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 [email protected]: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:

  • @react-native-firebase/analytics
  • @react-native-firebase/app
  • @react-native-firebase/crashlytics
  • @react-native-firebase/dynamic-links
  • @react-native-firebase/remote-config

Project Files

Javascript

Click To Expand

package.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:

# N/A

iOS

Click To Expand

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// 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:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->

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

RodolfoGS avatar Jun 23 '22 16:06 RodolfoGS

(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)

mikehardy avatar Jun 23 '22 17:06 mikehardy

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)
  1. Same result as 1
  2. Same as 1

RodolfoGS avatar Jun 23 '22 18:06 RodolfoGS

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 avatar Jun 23 '22 20:06 mikehardy

@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

mikehardy avatar Jun 23 '22 23:06 mikehardy

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

  • googleMobileAds: 9.6.0 +
  • use_frameworks! +
  • $RNGoogleMobileAdsAsStaticFramework = true

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:

  • react-native-applovin-max
  • react-native-flurry-sdk

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

In the meanwhile I will stay in 14.11.1

RodolfoGS avatar Jun 24 '22 01:06 RodolfoGS

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 avatar Jun 24 '22 02:06 mikehardy

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)

mikehardy avatar Jun 24 '22 02:06 mikehardy

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

lockieluke avatar Jun 24 '22 19:06 lockieluke

@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

mikehardy avatar Jun 24 '22 19:06 mikehardy

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

lockieluke avatar Jun 24 '22 19:06 lockieluke

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

mikehardy avatar Jun 24 '22 19:06 mikehardy

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

nbonatsakis avatar Jun 25 '22 04:06 nbonatsakis

@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

  1. figure out how to set $RNFirebaseAsStaticFramework = true

and

  1. 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!)

mikehardy avatar Jun 25 '22 04:06 mikehardy

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).

nbonatsakis avatar Jun 26 '22 02:06 nbonatsakis

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 avatar Jun 26 '22 04:06 mikehardy

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 avatar Jun 30 '22 16:06 mikehardy

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.

ahnafnafee avatar Jul 01 '22 02:07 ahnafnafee

This fixed it for me:

  1. Add expo-build-properties package
expo add expo-build-properties
  1. Update app.json to include:
{
  "expo": {
    "plugins": [
      [
        "expo-build-properties",
        {
          "ios": {
            "useFrameworks": "static"
          }
        }
      ]
    ]
  }
}

harterc1 avatar Jul 02 '22 19:07 harterc1

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

tux2nicolae avatar Jul 02 '22 20:07 tux2nicolae

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)

mikehardy avatar Jul 03 '22 18:07 mikehardy

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 ๐Ÿ‘

mahdieh-dev avatar Jul 04 '22 05:07 mahdieh-dev

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

mikehardy avatar Jul 04 '22 17:07 mikehardy

@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.

  • EDIT * Nevermind, the pods installation still fails... :/
 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

bombillazo avatar Jul 08 '22 22:07 bombillazo

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

dimaportenko avatar Jul 12 '22 12:07 dimaportenko

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

Khachik98 avatar Jul 12 '22 13:07 Khachik98

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?

LeandroTamola avatar Jul 12 '22 13:07 LeandroTamola

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

mikehardy avatar Jul 12 '22 16:07 mikehardy

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

marf avatar Jul 12 '22 19:07 marf

I was able to solve the issue by adding the following to the pod file

    use_frameworks!
    $RNFirebaseAsStaticFramework = true

And of course to disable the flipper

 # use_flipper!()

It works great on test development but getting an error when deploying it on a physical IOS device by cable

Error => -U and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together

So I'm kinda stuck there because of using of use_frameworks

DevJett avatar Jul 13 '22 03:07 DevJett

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.

DevJett avatar Jul 13 '22 06:07 DevJett

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

dimaportenko avatar Jul 13 '22 07:07 dimaportenko