Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null)) on Android devices #147824

Closed
EMUNES opened this issue May 4, 2024 · 5 comments
Labels
r: invalid Issue is closed as not valid

Comments

@EMUNES
Copy link

EMUNES commented May 4, 2024

Steps to reproduce

After upgrading to flutter 3.19.6, after sometime when I try to run flutter run on Android emulator API 34, I suddenly run into problems.

Expected results

Run smoothly like before, the app should open instead of hanging with async suspensions.

Actual results

Packages like path_provider and shared_preferences always report exception:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)

Rebuilding dependencies with flutter upgrade outdated_package, flutter clean, flutter pub cache clean do not work. App development has been suspended because of this wired one.

Code sample

Code sample
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await DeviceService().init();
  // Connect to local database.
  await ConfigService().initConfigurations();
  await DataStore().initDB();
  // Set applications paths.
  AppPaths().getPaths();
  // Media support.
  MediaKit.ensureInitialized();

  runApp(const ProviderScope(child: MyApp()));
}
  Future<void> initConfigurations() async {
    prefs = await SharedPreferences.getInstance();
  }
 Future<void> initDB() async {
    final dir = await getApplicationDocumentsDirectory();
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
INFO: Precompiled binaries are disabled
INFO: Building irondash_engine_context_native for x86_64-linux-android
INFO: Building irondash_engine_context_native for i686-linux-android
INFO: Building irondash_engine_context_native for x86_64-linux-android
INFO: Precompiled binaries are disabled
INFO: Building super_native_extensions for x86_64-linux-android
INFO: Building super_native_extensions for i686-linux-android
INFO: Building super_native_extensions for x86_64-linux-android
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:3979/aYLZeAx5_-I=/ws
I/flutter ( 4719): Running on sdk_gphone64_x86_64unknown

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.6, on Microsoft Windows [版本 10.0.22631.3527], locale zh-CN)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.6)
[✓] Android Studio (version 2023.3)
[✓] IntelliJ IDEA Community Edition (version 2024.1)
[✓] VS Code (version 1.89.0)
[✓] Proxy Configuration
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!
@EMUNES EMUNES changed the title Platform related packages report PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null)) PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null)) on Android devices May 6, 2024
@huycozy huycozy added the in triage Presently being triaged by the triage team label May 6, 2024
@huycozy
Copy link
Member

huycozy commented May 6, 2024

Hi @EMUNES
Your sample code above is production code and it's unclear which plugin is causing the issue. You should narrow down the issue by removing the usage of 3rd party plugins/packages one by one, unrelated/unaffected pages, and isolating the affected page into a minimal sample code that can produce the issue. And please share it here when you have such an example. Thanks!

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 6, 2024
@EMUNES
Copy link
Author

EMUNES commented May 6, 2024

Thanks @huycoz. I never thought a plugin can cause this big trouble to the project. Taking your suggestion, I can reproduce the exception if I had flutter_quill in my project. The exception persists from flutter_quill 9.0.0 to newest 9.3.10 version. The minimal example is as follows:

the minimal dependency in pubspec.yaml

name: fix
description: "A new Flutter project."
publish_to: "none"
version: 1.0.0+1

environment:
  sdk: ">=3.3.4 <4.0.0"

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^2.2.3 # Persistent settings.
  flutter_quill: "9.0.0"

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

the minimal production code to run

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final prefs = await SharedPreferences.getInstance();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

It looks like I have found the problem. Everything was fine before, it could be flutter pub upgrade certain dependencies under flutter_quill. Maybe I should raise an issue there?

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 6, 2024
@huycozy
Copy link
Member

huycozy commented May 6, 2024

Well, since you left shared_preferences in the sample code above, I re-checked this using its package example but couldn't reproduce the issue.

I think it may not issue of flutter_quill because I don't see it has platform implementation (it's a normal package as I can see) but it could be caused by a plugin that it's depending on, see its Platform Specific Configurations.

So, if the issue appears when you only import and use flutter_quill package, you should report the issue on its repository for better support there. In case you can narrow it down and find something new that you think this is a Flutter 1st party package bug, please write in comments.

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 6, 2024
@EMUNES
Copy link
Author

EMUNES commented May 6, 2024

Sure. I found that this issue only occur if shared_preferences is used with flutter_quill. Using shared_preferences with other dozens of packages in our project all works well. I will first check super_clipboard that flutter_quill depends on, which uses Platform Specific Configurations. If I find other problems, I will report.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 6, 2024
@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 7, 2024
@EMUNES
Copy link
Author

EMUNES commented May 10, 2024

It's a package issue related to rust language recent changes. Fixed by irondash/irondash#51.

@EMUNES EMUNES closed this as completed May 10, 2024
@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 10, 2024
@huycozy huycozy added r: invalid Issue is closed as not valid and removed in triage Presently being triaged by the triage team labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r: invalid Issue is closed as not valid
Projects
None yet
Development

No branches or pull requests

2 participants