Flutter on iOS: redefinition of module 'Firebase'

4,341

Solution 1

I've managed to resolve this issue by removing the firebase-ios-sdk dependency altogether. It appears that this is imported by the Flutter dependencies and adding it manually thus leads to a redefinition error.

I'd advise any people encountering this or similar errors to make sure that the integration steps they are following are meant for Flutter and not for iOS (only).

Solution 2

As Wouter Pol suggested, this error will most likely happen if you followed to many configuration guides and did some iOS-specific (non-Flutter) setup for Firebase.

I had to undo two changes:

1 - remove added code from AppDelegate.swift

Here is how it should look like - no import Firebase and no FirebaseApp.configure()

appdelegate.swift for firebase push notifications with flutter

2 - No package dependencies

I added the Firebase package before, but I don't need it when I already configured Flutter with appropriate packages. Here is how Runner > Swift Packages should look like:

Runner > Swift Packages - no dependencies for Firebase notifications with flutter

Solution 3

If you use M1 try this

arch -x86_64 pod install

Share:
4,341
Wouter Pol
Author by

Wouter Pol

Updated on January 03, 2023

Comments

  • Wouter Pol
    Wouter Pol over 1 year

    I've been trying to build my flutter app on iOS but flutter run is throwing the following error:

    /Users/<MyUser>/Desktop/projects/app/ios/Pods/Firebase/CoreOnly/Source
    s/module.modulemap:1:8: error: redefinition of module 'Firebase'
    module Firebase {
           ^
    /Users/<MyUser>/Library/Developer/Xcode/DerivedData/Runner-dbkgurnsasbvieahfnk
    dontejqss/SourcePackages/checkouts/firebase-ios-sdk/CoreOnly/Sources/module.
    modulemap:1:8: note: previously defined here
    module Firebase {
    

    I've imported the firebase-ios-sdk as per the instructions here. The imported modules are FirebaseCore, FirebaseAuth and FirebaseMessaging. I have not made any modifications to iOS-specific code (anything under /ios) apart from importing Firebase in the AppDelegate.swift file. The updated file now contains the following code:

    import UIKit
    import Flutter
    import Firebase
    
    @UIApplicationMain
    @objc class AppDelegate: FlutterAppDelegate {
      override func application(
      _ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
     ) -> Bool {
       FirebaseApp.configure()
       GeneratedPluginRegistrant.register(with: self)
       return super.application(application, didFinishLaunchingWithOptions: launchOptions)
     }
    }
    

    After searching the error I've tried the following steps:

    • flutter clean
    • pod deintegrate and pod install
    • Cleaning DerivedData (both through XCode and manually)
    • Remove and re-add firebase-ios-sdk

    But to no avail.

  • Wouter Pol
    Wouter Pol over 2 years
    Unfortunately I'm not using a M1-cpu. I've tried it nonetheless but, as one might have expected, it did nothing to resolve the issue.
  • Christian Leon
    Christian Leon about 2 years
    I don't even have this one lol
  • ΞΫΛL
    ΞΫΛL about 2 years
    Thanks! That solved it for me! For others that might be looking for this, that is in Xcode → Projects → Runner → Package dependencies
  • ZXERSTON
    ZXERSTON about 2 years
    @ΞΫΛL Hi! I can't seem to find package dependencies folder/file under my runner. Can you enlighten me on this matter?
  • ΞΫΛL
    ΞΫΛL about 2 years
    Try this guide: !removing dependencies