26

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
  • 1,031
  • 1
  • 8
  • 16

3 Answers3

63

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

Guide to remove dependencies (as suggested by ΞΫΛL): removing dependencies

Wouter Pol
  • 1,031
  • 1
  • 8
  • 16
28

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

Aleksandar
  • 3,558
  • 1
  • 39
  • 42
3

If you use M1 try this

arch -x86_64 pod install

Taz
  • 1,737
  • 1
  • 15
  • 30
  • 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. – Wouter Pol Jan 20 '22 at 13:33