Unable to initialize FirebaseApp - Flutter

Viewed 3008

My project suddenly stopped running properly - it is unable to initialize FirebaseApp.

I've been using an old-fashioned Firebase configuration - Google-Services files directly from Firebase console. I switched to the command flutterfire configure but the error isn't gone. I also tried to delete whole ios directory and try to run flutterfire configure again, but still no results.

Error:

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
#0      FirebaseCoreHostApi.initializeCore (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:205:7)
<asynchronous suspension>
#1      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:29:44)
<asynchronous suspension>
#2      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:73:7)
<asynchronous suspension>
#3      Firebase.initializeApp (package:firebase_core/src/firebase.dart:40:31)
<asynchronous suspension>
#4      main (package:traveler/main.dart:12:3)
<asynchronous suspension>

Line causing the issue:

  // Placed after WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

flutter doctor -v:

[✓] Flutter (Channel master, 3.1.0-0.0.pre.1310, on macOS 12.4 21F79 darwin-arm, locale en-PL)
    • Flutter version 3.1.0-0.0.pre.1310 at /Users/wiktor/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 91603595d1 (13 days ago), 2022-06-18 19:14:07 -0400
    • Engine revision 3ac96a1f40
    • Dart version 2.18.0 (build 2.18.0-190.0.dev)
    • DevTools version 2.14.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/wiktor/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13F17a
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] Android Studio
    • Android Studio at /Users/wiktor/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.7905991/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] Android Studio
    • Android Studio at /Users/wiktor/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.7863044/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] IntelliJ IDEA Ultimate Edition (version 2021.1.2)
    • IntelliJ at /Users/wiktor/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[✓] IntelliJ IDEA Ultimate Edition (version 2021.1.2)
    • IntelliJ at /Users/wiktor/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/211.7442.40/IntelliJ IDEA.app
    • Flutter plugin version 68.1.1
    • Dart plugin version 211.7817

[✓] Connected device (3 available)
    • iPod touch (7th generation) (mobile) • BAEBD16B-8BA9-4D2F-B86D-38282E5FA060 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
    • macOS (desktop)                      • macos                                • darwin-arm64   • macOS 12.4 21F79 darwin-arm
    • Chrome (web)                         • chrome                               • web-javascript • Google Chrome 103.0.5060.53

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

8 Answers

This issue has happened in the latest firebase_core_platform_interface, so overriding the older version of that would solve the issue for now. (It can be removed once the Firebase team fixes it)

dependency_overrides:
  firebase_core_platform_interface: 4.4.1

This issue is now resolved in version 1.19.1

firebase_core: ^1.19.1

According to this issue shared by @Hardik Mehta, New SDKs don't compile and old SDK version. A solution that worked for me is to upgrade firebase packages, delete ios/Podfile.lock and run pod install --repo-update.

I have updated the below dependency:

dependency_overrides:
 firebase_core_platform_interface: 4.4.1

Executed this command and updated firebase dependencies

flutter pub upgrade firebase_core

flutter pub upgrade firebase_messaging

it is working properly now.

The problem seems to be with the core platform interface. Add firebase_core_platform_interface: 4.4.0 to pubspec.yaml. You might have to downgrade all other firebase dependencies.

I've the same error but in different context: the app was correctly building and running on both iOS and Android if launched from by Android Studio (even in release mode), but whenever I deployed it using codemagic, I got a non functioning app on the Play Store and App Store that was showing a white screen and giving me the following error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
#0     FirebaseCoreHostApi.initializeCore (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:199)
<asynchronous suspension>
#1     MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:29)
<asynchronous suspension>
#2     MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:73)
<asynchronous suspension>
#3     Firebase.initializeApp (package:firebase_core/src/firebase.dart:42)
<asynchronous suspension>
#4     main (package:my_family/main.dart:43)
<asynchronous suspension>

Codemagic and my android studio were using the same versions of Flutter, Xcode and pod.

I solved the problem adding the following right before dependencies:

dependency_overrides:
  firebase_core_platform_interface: 4.4.0

I'm using old firebase libraries and the version 4.4.1 did not solve the problem.

My firebase libraries:

  firebase_core: 1.12.0
  firebase_auth: 3.3.6
  firebase_storage: 10.2.6
  firebase_messaging: 11.2.6
  cloud_firestore: 3.1.7

I update all of my firebase packages to the latest version and then the issue was fixed.

try "Flutter upgrade" on terminal. i

Related