Calling Firebase.initializeApp() returns 'Unable to establish connection on channel' - Flutter + Firebase

Viewed 8144

I'm working with Firebase in flutter (latest versions as of 1st July 2022), and when I try to call Firebase.initializeApp() in my Main function, it returns an error of:

'[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)'

Here is my code:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  Firebase.initializeApp();
  runApp(const MyApp());
}

Any help would be greatly appreciated

7 Answers

I was able to solve the problem by upgrading all my firebase dependencies to the latest version using flutter pub outdated and flutter pub upgrade firebase_....

I encountered this issue after adding the firebase_messaging plugin v11.4.4. Might be related to the change in firebase_core_platform_interface.

Also got it after a pub update. Fixed it by doing: flutter clean and removing the pubspec.lock

Do a flutter clean and upgrade firebase core with

    flutter pub upgrade firebase_core

The run

    dart pub global activate flutterfire_cli
    flutterfire configure

to reinitialize firebase. I experienced this after adding app_check support

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.

Problem seems to be with the core platform interface. Add firebase_core_platform_interface: 4.4.0 and adjust all other firebase deps to make them compatible with this library. I downgraded all versions to 36 day old release and it finally works.

Had the same problem and scaled back (thank you git) - getting flutter dependencies right - as in it compiles and work as advertised is no mean feat. Welcome :)

I just built a new flutter app and I got this error when initializing Firebase App and running it in the browser and not the android emulator. I am using VS Code and you can change the target device in the bottom task bar on the right side.

Solution is to run it in the android emulator. I don't know if there are permissions to be set for web view but I do not plan on deploying to web.

Related