Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter on iOS: redefinition of module 'Firebase'

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.

like image 971
Wouter Pol Avatar asked Sep 02 '25 17:09

Wouter Pol


2 Answers

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

like image 154
Wouter Pol Avatar answered Sep 04 '25 07:09

Wouter Pol


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

like image 41
Aleksandar Avatar answered Sep 04 '25 07:09

Aleksandar