MsPoojitha
MsPoojitha

Reputation: 693

Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)

Suddenly this error appears in the debug console. I do not know what I did wrong.

Error image

Upvotes: 69

Views: 148911

Answers (15)

kashlo
kashlo

Reputation: 2617

for me only flutter pub cache clean helped with the issue

Upvotes: 0

Saurav Gawali
Saurav Gawali

Reputation: 31

In my case, This line was missing in MainAcitivty.java

GeneratedPluginRegistrant.registerWith(flutterEngine);

with it's import

import io.flutter.plugins.GeneratedPluginRegistrant;

enter image description here

Upvotes: 0

Sheraz Asghar
Sheraz Asghar

Reputation: 37

This is not an answer but some checks which you may forget while adding a new package.

Try to restart the project by terminating the currently running session.

Run the commands proposed as Answer.

The last check could be to confirm whether the added package supports the current running platform.

For example, I was using fluttertoast on windows development platform which is not supported for windows till this date that's why I was facing the same error.

Upvotes: -3

Jonathan Ellis
Jonathan Ellis

Reputation: 5479

I spent a long time looking into this and eventually traced it to the plugin registrar being nil when setting up the plugin.

This was caused by setting my iOS app root view controller to anything other than FlutterViewController (i.e. in my case, I had a UINavigationController as the root). This will result in a failure to register all your plugins.

The app delegate assumes that the root view controller is a FlutterViewController, so if it isn't then you will need to re-direct all plugin-related function calls to your FlutterViewController from your app delegate.

You can do this by overriding these functions as follows in AppDelegate.swift:

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {

    var flutterViewController: FlutterViewController!

    override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        // Wherever your FlutterViewController is in your view hierarchy, you need to get a reference to it:
        let navController = window!.rootViewController as! UINavigationController
        self.flutterViewController = navController.children.first as! FlutterViewController

        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }

    // Add these overrides to redirect all the FlutterAppDelegate functions to your flutterViewController:

    override func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar? {
        flutterViewController.registrar(forPlugin: pluginKey)
    }

    override func hasPlugin(_ pluginKey: String) -> Bool {
        flutterViewController.hasPlugin(pluginKey)
    }

    override func valuePublished(byPlugin pluginKey: String) -> NSObject? {
        flutterViewController.valuePublished(byPlugin: pluginKey)
    }

}

Upvotes: 13

mohammad reza shabani
mohammad reza shabani

Reputation: 79

I had same problem with webview_flutter package , after longtime and more search found this package has confilic with one another packages in may case it was "wear" package , after delete that its worked

Upvotes: -1

matt3o
matt3o

Reputation: 653

Try out different devices like Chrome or Android if you run into this error. Note that firebase does not run on all platforms flutter runs on.

In my case I was developing on Linux and got that PlatformException because I was launching the app as a Linux program - which is not supported by Firebase and thus raises the error even though everything is configured correctly.

Upvotes: 0

ghifari.akbar
ghifari.akbar

Reputation: 175

Running flutter clean and flutter pub get worked for me.

Upvotes: 5

I was facing the same issue, After 1 day of trying, I realized that the variable I was passing to createUserWithEmailAndPassword() had no value. This function was working totally fine when I was passing hardcoded value i.e. email & password

Upvotes: 2

Xavier Soh
Xavier Soh

Reputation: 165

In my case i was trying to use "google_mobile_ads" and "admob_flutter" at the same time. You must choose one only.

Upvotes: 0

Sajith Madushanka
Sajith Madushanka

Reputation: 39

I also effected from that issue for few hours, finally I found issue that was I ran my emulator as windows (:, yeah please run with Android emulator you selected vm.

Upvotes: 0

Ali Bagheri
Ali Bagheri

Reputation: 3419

I was have this problem. after downgrade awesome_notifications package to 0.6.21, resolved this.

Upvotes: -1

Baqar Naqvi
Baqar Naqvi

Reputation: 29

If you are using these dependecies then replace it with a latest version:

  • firebase_messaging
  • firebase_core
  • flutter_local_notifications

Then in android/app/build.gradle update compileSdkVersion flutter.compileSdkVersion to 33

Upvotes: 1

Dheeraj Bhavsar
Dheeraj Bhavsar

Reputation: 57

Please also check the compileSdkVersion in android/app/build.gradle and update it to 33

Upvotes: 1

Ariel H.
Ariel H.

Reputation: 1116

You've upgraded Flutter but not the packages. In the terminal enter

flutter pub outdated

Then upgrade the outdated packages one by one like this:

flutter pub upgrade outdated_package

After you're finished:

flutter clean

and

flutter pub get

Your problem should now be solved.

Upvotes: 91

John Oyekanmi
John Oyekanmi

Reputation: 386

I had the same issue and stumped on this post.

In my case I was able to detect which plugin was in fact giving the error and it turned out to be firebase_core. So, I decided to upgrade the package to the latest version which happened to be 1.21.1 in my case.

So, to solve the issue I will suggest you try changing the version of the firebase_core package you're using to the latest in the pubspec.yaml file of your project like so:

firebase_core: ^1.21.1 (replace with latest verison)

Or you can just run:

flutter pub upgrade firebase_core

This will upgrade firebase_core to the latest version.

Or you can as well put any as the version code in the pubspec.yaml file of your project like so:

firebase_core: any (upgrades firebase_core to the latest verison)

Upvotes: 7

Related Questions