flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_core] use with Firebase Emulator demo project.

Open bsr203 opened this issue 3 years ago • 4 comments

This is reported previously. Please refer to https://github.com/firebase/flutterfire/issues/8898

What works:

  • run flutterfire configure and create the option file.
  • load it through
  await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
)
..

// set the emulators
FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
await FirebaseAuth.instance.useAuthEmulator('localHost', 9099);

now you can connect to the emulator running with the actual project id (same used to configure through flutterfire configure)

What doesn't work:

  • start the emulator with a demo project. see https://firebase.google.com/docs/emulator-suite/connect_firestore The reason to use the demo project, as described in the docs
We recommend you use demo projects wherever possible. Benefits include:

Easier setup, since you can run the emulators without ever creating a Firebase project
Stronger safety, since if your code accidentally invokes non-emulated (production) resources, there is no chance of data change, usage and billing
Better offline support, since there is no need to access the internet to download your SDK configuration.

  • if you use the flutter fire configuration like
  await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
)

it starts up the app, but connect with real project not the emulator. That is if you seed the demo-test project (firestore, auth,..) you won't see it in the app.

I tried with changing the projectId alone in the FirebaseOptions. Which causes a crash

Connecting to VM Service at ws://127.0.0.1:51172/ATxL0xfCjfA=/ws
2022-09-09 16:37:17.438 myapp[14449:1525198] *** Terminating app due to uncaught exception 'com.firebase.core', reason: 'Configuration fails. It may be caused by an invalid GOOGLE_APP_ID in GoogleService-Info.plist or set in the customized options.'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007ff8191597c3 __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff818eb9bc3 objc_exception_throw + 48
	2   CoreFoundation                      0x00007ff81915962a +[NSException exceptionWithName:reason:userInfo:] + 0
	3   FirebaseCore                        0x000000010f0d7f9e +[FIRApp addAppToAppDictionary:] + 254
	4   FirebaseCore                        0x000000010f0d7203 +[FIRApp configureWithName:options:] + 1347
	5   myapp                                0x000000010ef0bfd4 -[FLTFirebaseCorePlugin initializeAppAppName:initializeAppRequest:completion:] + 2308

if I remove all config, like

await Firebase.initializeApp();
[ERROR:flutter/runtime/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

so how would you connect to the emulator which is running a demo project .

cc @russellwheatley

bsr203 avatar Sep 09 '22 20:09 bsr203

Thanks for the report @bsr203 I tried the scenario you mentioned, but didn't get the error you reported.

  1. I have the demo project configured and running:
Screenshot 2022-09-12 at 4 45 40 PM
  1. Used firebase_auth_example plugin that has FirebaseAuth emulator setup and configured:
Screenshot 2022-09-12 at 4 34 27 PM

This error Terminating app due to uncaught exception 'com.firebase.core', reason: 'Configuration fails. It may be caused by an invalid GOOGLE_APP_ID in GoogleService-Info.plist or set in the customized options.' *** First throw call stack: probably indicates GoogleService-Info.plist is not in sync or configured per the platform.

how would you connect to the emulator which is running a demo project .

Please check this and see if it helps.

darshankawar avatar Sep 12 '22 11:09 darshankawar

@darshankawar I have seen that SO link, and similar.

You are getting GoogleService-Info.plist error because, you haven't run flutterfire configure which downloads the firebase configuration files.

Once you configure, you have a catch22 situation where you have to initialize it with the real configuration, which then would not connect to the demo project.

bsr203 avatar Sep 12 '22 13:09 bsr203

Thanks for the feedback. Keeping this issue open and labeling for further insights from the team on expected behavior when connect to the emulator which is running a demo project.

/cc @russellwheatley

darshankawar avatar Sep 13 '22 08:09 darshankawar

This is an issue I am facing as well. @darshankawar I think the desired solution, is that when running flutterfire configure, you are given the option to select 'use demo project' or something similar.

Related note. The firebase docs recommend using demo projects with the emulator when possible, but then go into absolutely ZERO detail about how it should be done. This fact, in addition to the fact that it is clear the FlutterFire team has given very little thought into how to run a demo project, all comes of as Firebase is not even a production ready service. I hope one day Firebase will get their act together and present itself as a tool for serious application development.

Turburlar avatar Dec 28 '22 22:12 Turburlar