Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Flutter: Firebase.initializeApp fails with Unable to establish connection on channel

ErrorUnable to establish connection on channel

Short answer

The Dart side of firebase_core could not reach its native half. That usually means the app was not fully rebuilt after adding Firebase, Firebase was never configured with flutterfire configure, or main() calls initializeApp before the Flutter binding exists. Fix the setup code, then stop the app and run it again.

  • Applies to Flutter 3, firebase_core
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Compare your main() with the one in the Firebase setup guide, then check that firebase_options.dart exists.

    sed -n 1,30p lib/main.dart && ls lib/firebase_options.dart
  2. 2Match what you see, then jump to its fix

    1. 1The error appears right after flutter pub add firebase_core, with the old app still runningThe app was hot-reloaded, not rebuilt, after adding FirebaseFix
    2. 2lib/firebase_options.dart does not exist or main.dart does not pass optionsFirebase is not configured for this appFix
    3. 3initializeApp is called inside a non-async main, or before WidgetsFlutterBinding.ensureInitializedmain() does not follow the documented initialization orderFix
    4. 4The error is Android only, and android/app/google-services.json is missingThe Android build has no Google services plugin or config fileFix

What does the error look like?

  • Unable to establish connection on channel

Cause 1 of 4

The app was hot-reloaded, not rebuilt, after adding Firebase

1Check

Native plugin code only exists in a new build. Check that the plugin is in pubspec.lock.

grep -n "firebase_core" pubspec.lock

2Fix

Stop the running app completely and run it again, so Gradle and Xcode build the plugin.

flutter pub get
flutter run

3Verify

initializeApp completes without an exception.

flutter run -v

Confirmed by firebase.google.com

Did this fix it?

Cause 2 of 4

Firebase is not configured for this app

1Check

flutterfire configure creates firebase_options.dart in lib/. Look for it and for the options argument.

grep -n "DefaultFirebaseOptions" lib/main.dart

2Fix

Log in, activate the FlutterFire CLI, run configure, and pass the generated options to initializeApp.

firebase login
dart pub global activate flutterfire_cli
flutterfire configure

3Verify

lib/firebase_options.dart exists and the app starts.

ls lib/firebase_options.dart

Confirmed by firebase.google.com

Did this fix it?

Cause 3 of 4

main() does not follow the documented initialization order

1Check

Read main() and confirm the binding call comes first and main is async.

grep -n -B3 -A6 "void main\|Future<void> main" lib/main.dart

2Fix

Use the same order as the setup guide: ensureInitialized, awaited initializeApp with options, then runApp.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

3Verify

Cold start the app; the exception should not return.

flutter run

Confirmed by firebase.google.com

Did this fix it?

Cause 4 of 4

The Android build has no Google services plugin or config file

1Check

The file must be in the app module, and the Gradle plugin must be applied.

ls android/app/google-services.json

2Fix

Run flutterfire configure again, and confirm the plugin is declared as the Android setup guide shows.

flutterfire configure

3Verify

Build for Android and start the app.

flutter run

Confirmed by firebase.google.com

Did this fix it?

How do I stop it coming back?

  • Add each Firebase plugin with flutter pub add, then run flutterfire configure and do a full rebuild.
  • Commit firebase_options.dart so every teammate starts from the same configuration.
  • Keep Firebase.initializeApp as the first awaited call in main().

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Firebase says no default app exists when you call a service

FirebaseAppError: The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.

A Firebase service was asked for the default app before initializeApp ran in that same module scope, or on a different copy of the package.

3 causes, each with a fix

Mobile apps

Flutter Android: Failed to load FirebaseOptions from resource

Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.

On Android, Firebase reads its settings from a values.xml file that the Google services Gradle plugin builds from google-services.json.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.