Swift pods cannot yet be integrated as static libraries FirebaseCoreInternal-library

Viewed 19552

I am building an app by Flutter. I got this error message when doing "pod install" or "pod install --repo-update" or "pod update" and the pod install failed and stopped.

The error message:

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

The Swift pod FirebaseCoreInternal-library depends upon GoogleUtilities-library, 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.

My Podfile:

platform :ios, '11.0'

...

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

...
9 Answers

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 in ios/Podfile:

  platform :ios, '12.4'
  ...
  ...
  
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCoreInternal', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  #....add any library need headers

Best

For newest version of firebase 15.1.1 with react-native 0.69.1 no need to enable use_frameworks because it will lead to errors in deploying in real devices

So you just need to add the firebase modulars and set headers to true.

     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 Android and IOS on real devices and it works great!

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

-

UPDATED 20/Jul

If you wanted to use rich content notifications like notifications with images. Following this article by firebase will ask you to enable use_frameworks as well so my solution for that is to use modular_headers => true for the following packages

target 'richNotification' do
    pod 'FirebaseCoreInternal', :modular_headers => true
    pod 'Firebase/Messaging', :modular_headers => true
    pod 'GoogleUtilities', :modular_headers => true
end

NOTE: Make sure richNotification target is at the bottom of the podfile. see below how my final 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()

#     use_frameworks! :linkage => :static
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  $RNFirebaseAsStaticFramework = true
  # Flags change depending on the env values.


  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

target 'richNotification' do
    pod 'FirebaseCoreInternal', :modular_headers => true
    pod 'Firebase/Messaging', :modular_headers => true
    pod 'GoogleUtilities', :modular_headers => true
end

I tested it on both Android and IOS, it works great!!

For Testing Send the following JSON data to https://fcm.googleapis.com/fcm/send as a"POST", and make sure to put in the headers "mutable-content": "1", See the screenshot below

{
        "to": " Put here your mobile fcm token ",
        "notification": {
            "title": "You have received a new request",
            "body": "Radiohead - Street Spirit (Fade Out)",
            "content_available" : "true",
            "priority" : "high",
            "sound":"defualt",
            "image": "https://i.ytimg.com/vi/LCJblaUkkfc/hq720.jpg"
        },
        "android": {
          "priority": "high",
          "notification": {
            "imageUrl": "https://www.youtube.com/watch?v=o3mP3mJDL2k"
          }
        },
        "apns": {
          "payload": {
            "aps": {
              "mutable-content": "1",
              "content-available": "true",
            },
            "imageUrl": "https://i.ytimg.com/vi/panR4xwt0wM/hqdefault.jpg",
            "fcm_options": {
              "imageUrl": "https://i.ytimg.com/vi/panR4xwt0wM/hqdefault.jpg"
            }
          },
          "headers": {
            "mutable-content": "1",
            "apns-push-type": "background",
            "apns-priority": "5", 
            "apns-topic": "com.paidtabs" 
          }
        },
        "webpush": {
          "headers": {
            "image": "https://koenig-media.raywenderlich.com/uploads/2021/01/good_news_petsicon.png"
          }
        },
        "data":{
          "passingDataToApp" : "Mario",
          "body" : "great match!",
          "Room" : "PortugalVSDenmark"
        }
      }

Headers look like headers

Removing use_frameworks because is conflicting with use_flipper and adding all this libs worked for me

  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'FirebaseCoreInternal', :modular_headers => true  
  pod 'FirebaseStorageInternal', :modular_headers => true
  pod 'FirebaseCoreExtension', :modular_headers => true
  pod 'FirebaseAppCheckInterop', :modular_headers => true
  pod 'FirebaseAuthInterop', :modular_headers => true
  pod 'FirebaseMessagingInterop', :modular_headers => true
  pod 'GTMSessionFetcher', :modular_headers => true
  pod 'FirebaseAppCheckInterop', :modular_headers => true
  pod 'FirebaseAuthInterop', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true

Heads up! FirebaseFunctions-h.swift and FirebaseStorage-h.swift requires use_frameworks, so probably you may have an error with these files. Perhaps you may prefer use axios or similar lib to invoke your endpoint api and/or aws s3 to save your file instead.

Finally after going through so many questions the answer was to user Flipper and modular_header in same time, finally my Pod file looks like this :-

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 'MyPregnancy' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCoreInternal', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => 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 'MyPregnancyTests' 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

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;

pod 'GoogleUtilities', :modular_headers => true;

add this line to podfile

Add to Podfile and update pod

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

Just a heads up for those desperately trying to fix this, using the newest packages, you may end up dealing with the warning "concurrency is only supported in IOS 15". That looks to be a dead end. It may be in your best interest to downgrade the package and wait for react native +70.0.

Related