Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [firebase_core] Firebase.initializeApp fails with error when using Firebase Emulator demo project. #8898

Closed
Turburlar opened this issue Jun 13, 2022 · 8 comments
Labels
platform: android Issues / PRs which are specifically for Android. plugin: cloud_firestore plugin: core type: bug Something isn't working

Comments

@Turburlar
Copy link

Turburlar commented Jun 13, 2022

I am using the Firebase Emulator to develop.

I am using a Firebase Emulator demo project that has no associated firebase/gcp cloud project actually created.

A demo project is defined here: https://firebase.google.com/docs/emulator-suite/connect_firestore

I use the following command to start the emulator with a specific demo project name...

firebase emulators:start --project demo-test --only firestore

The emulator successfully starts and hosts at localhost:8080.

Then when I try to run initializeApp in my Firebase Project as follows...

await Firebase.initializeApp(name: "demo-test");
    FirebaseFirestore.instance.settings = const Settings(
      host: 'localhost:8080',
      sslEnabled: false,
      persistenceEnabled: false,
    );

I get the following error...

Restarted application in 2,058ms.
E/flutter ( 7724): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.
E/flutter ( 7724):
E/flutter ( 7724): Usually this means you've attempted to use a Firebase service before calling `Firebase.initializeApp`.
E/flutter ( 7724):
E/flutter ( 7724): View the documentation for more information: https://firebase.flutter.dev/docs/overview#initialization
E/flutter ( 7724):
E/flutter ( 7724): #0      MethodChannelFirebase.initializeApp
package:firebase_core_platform_interface/…/method_channel/method_channel_firebase.dart:113
E/flutter ( 7724): <asynchronous suspension>
E/flutter ( 7724): #1      Firebase.initializeApp
package:firebase_core/src/firebase.dart:40
E/flutter ( 7724): <asynchronous suspension>
E/flutter ( 7724): #2      _MyHomePageState._asyncInit
package:mobile_app/main.dart:53
E/flutter ( 7724): <asynchronous suspension>
E/flutter ( 7724):

The expected behaviour is that Firebase should be able to be initialized with a pure emulator demo project.

@Turburlar Turburlar added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Jun 13, 2022
@maheshmnj
Copy link
Member

maheshmnj commented Jun 14, 2022

Hi @Turburlar, Thanks for filing the issue After firebase initialization can you please try defining your settings by running

 FirebaseFirestore.instance
        .useFirestoreEmulator('localhost', 8080, sslEnabled: false);

@maheshmnj maheshmnj added blocked: customer-response Waiting for customer response, e.g. more information was requested. triage Issue is currently being triaged. and removed Needs Attention This issue needs maintainer attention. labels Jun 14, 2022
@Turburlar
Copy link
Author

I have updated my code to take into account your suggestion.

The following code gives the same error...

    await Firebase.initializeApp();
    FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080, sslEnabled: false);

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jun 17, 2022
@Turburlar
Copy link
Author

@maheshmnj Can you remove the blocked:customer-response tag please.

@maheshmnj
Copy link
Member

@Turburlar It was removed when you commented.

@darshankawar
Copy link

@Turburlar
Try by calling WidgetsFlutterBinding.ensureInitialized(); before initializing your app.
ie

WidgetsFlutterBinding.ensureInitialized();
 await Firebase.initializeApp();

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Jun 20, 2022
@Turburlar
Copy link
Author

Here is the last version of my complete app. The same error as listed persists with the following code, which takes into account your suggestions...

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080, sslEnabled: false);
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Test App"),
      ),
      body: const Center(
        child: Text("temp"),
      ),
    );
  }
}

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jun 20, 2022
@darshankawar
Copy link

Thanks for the update. Using the code sample above and initiating firebase emulator with the command provided above, I am getting same error as reported:

Launching lib/main.dart on iPhone 13 in debug mode...
Running pod install...
Running Xcode build...
Xcode build done.                                           55.8s
Debug service listening on ws://127.0.0.1:50903/UT_SjCI4aPo=/ws
Syncing files to device iPhone 13...
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.

Usually this means you've attempted to use a Firebase service before calling `Firebase.initializeApp`.

View the documentation for more information: https://firebase.flutter.dev/docs/overview#initialization

#0      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:113:9)
<asynchronous suspension>
#1      Firebase.initializeApp (package:firebase_core/src/firebase.dart:40:31)
<asynchronous suspension>
#2      main (package:testdemo/main.dart:7:3)
<asynchronous suspension>

Screenshot 2022-06-21 at 12 57 35 PM

@darshankawar darshankawar added plugin: cloud_firestore plugin: core platform: android Issues / PRs which are specifically for Android. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels Jun 21, 2022
@russellwheatley
Copy link
Member

You haven't setup Firebase correctly. Ensure you have ran flutterfire configure in the root of your app directory and setup the platforms you require.

@firebase firebase locked and limited conversation to collaborators Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: android Issues / PRs which are specifically for Android. plugin: cloud_firestore plugin: core type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants