A Firebase App named "[DEFAULT]" already exists

1,765

Solution 1

I had similar issue when create firebase app by flavors using flutterfire CLI. I realized that flutterfire create apps with same name in different projects. Then I tried 2 ways and it works.

  • 1st: manually change app name in each firebase project.

  • 2nd: add param name when initialize such as in main_dev.dart

     await Firebase.initializeApp(
     name: "dev project",
     options: DefaultFirebaseOptions.currentPlatform);
    

Solution 2

Got this error after fumbling with firebase projects and upgrading packages.

Fixed by

flutter clean
flutter pub get

then build the project again.

I have apps with same name in different projects, this doesn't seem to cause the error.

Share:
1,765
K_Chandio
Author by

K_Chandio

Updated on January 03, 2023

Comments

  • K_Chandio
    K_Chandio over 1 year

    I have my flutter App integrated with firebase, everything was fine but when I migrated firebase project to client firebase console, added his google services file, changed DefaultFirebaseOption.currentplatform file credentials but I got error whenever I try to run my app. My main method looks like this:

    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
      token = await FirebaseMessaging.instance.getToken();  
      Provider.debugCheckInvalidValueType = null;
      runApp(const MyApp());
    }

    The error is:

    E/flutter (28330): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [core/duplicate-app] A Firebase App named "[DEFAULT]" already exists.

    I searched here and found a solution from here and updated my main method like this:

    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
       if (Firebase.apps.isNotEmpty) {
         await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
       }else{
         Firebase.app()
       }
      //await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
      token = await FirebaseMessaging.instance.getToken();  
      Provider.debugCheckInvalidValueType = null;
      runApp(const MyApp());
    }

    but this time I got no error but my app UI is not showing, I just see black screen. I have been trying to solve this from 4 to 5 hours but found no solution.any Help will highly be appreciated.

    Update I provide name parameter in both of the scenrios and my app worked fine for first time i install, but when i retart or close app and re run it, I got same error as mentioned in above cases.

    • luis
      luis about 2 years
      I think the condition should be different like: ``` if(Firebase.apps.isEmpty) { await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); } ```
  • Gopal Kohli
    Gopal Kohli almost 2 years
    it worked with adding name