superlistapp / super_native_extensions

Native drag & drop, clipboard access and context menu.
MIT License
330 stars 50 forks source link

BUG: super_clipboard Cause PlatformException(channel-error, Unable to establish connection on channel., null, null) on Android devices #353

Closed EMUNES closed 5 days ago

EMUNES commented 1 week ago

I found this exception always occur on Android devices, if I use super_clipboard (or packages depending on super_clipboard, like flutter_quill) with shared_preferences package. I can use shared_preference with other dozens of packages, but once with super_clipboard, the exception occurs which I can not get rid of. I report this BUG here because this is the only platform-related package I can find to cause this problem.

This exception will cause Android app unable to open. The app will hang.

This exception won't occur on Windows11 build. It won't occur if super_clipboard is the only package dependency.

ENV: flutter version: 3.19.6 and dart 3.3.4, Windows 11 VERSION: supper_clipboard 0.7.3 up to 0.8.12

Minimal code for reproduce:

pubspec.yml:

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"
  super_clipboard: "0.7.3" # up to "8.0.12"
  # flutter_keyboard_visibility: ^6.0.0 # no problem.
  # url_launcher: ^6.2.6 # no problem.
  # device_info_plus: ^10.1.0 # no problem.

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

Main 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(); // Exception here.

  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();
  }
}
dovecheng commented 1 week ago

降级这个依赖可以编译运行 Downgrade this dependency to compile and run

我还卸载了 rust. I also uninstalled rust.

flutter.ndkVersion: 23.1.7779620 cmdline-tools: latest

dependency_overrides:
  irondash_engine_context: 0.5.1
EMUNES commented 1 week ago

Sorry in my case, simply downgrading irondash_engine_context does not work. I didn't uninstall rust, because we need it in our environment.

knopp commented 1 week ago

Can you post here verbose log from flutter build?

EMUNES commented 1 week ago

Sure

[ +331 ms] Running Gradle task 'assembleDebug'... (completed in 9.2s)
[   +3 ms] Calculate SHA1: LocalDirectory: 'C:\my\Tut\fix\build\app\outputs\flutter-apk'/app-debug.apk
[+1696 ms] √  Built build\app\outputs\flutter-apk\app-debug.apk.
[   +2 ms] executing: C:\Users\HZB\AppData\Local\Android\sdk\build-tools\34.0.0\aapt dump xmltree C:\my\Tut\fix\build\app\outputs\flutter-apk\app-debug.apk AndroidManifest.xml
[  +51 ms] Exit code 0 from: C:\Users\HZB\AppData\Local\Android\sdk\build-tools\34.0.0\aapt dump xmltree C:\my\Tut\fix\build\app\outputs\flutter-apk\app-debug.apk AndroidManifest.xml
[        ] N: android=http://schemas.android.com/apk/res/android
             E: manifest (line=2)
               A: android:versionCode(0x0101021b)=(type 0x10)0x1
               A: android:versionName(0x0101021c)="1.0.0" (Raw: "1.0.0")
               A: android:compileSdkVersion(0x01010572)=(type 0x10)0x22
               A: android:compileSdkVersionCodename(0x01010573)="14" (Raw: "14")
               A: package="com.example.fix" (Raw: "com.example.fix")
               A: platformBuildVersionCode=(type 0x10)0x22
               A: platformBuildVersionName=(type 0x10)0xe
               E: uses-sdk (line=7)
                 A: android:minSdkVersion(0x0101020c)=(type 0x10)0x17
                 A: android:targetSdkVersion(0x01010270)=(type 0x10)0x21
               E: uses-permission (line=15)
                 A: android:name(0x01010003)="android.permission.INTERNET" (Raw: "android.permission.INTERNET")
               E: queries (line=23)
                 E: intent (line=24)
                   E: action (line=25)
                     A: android:name(0x01010003)="android.intent.action.PROCESS_TEXT" (Raw: "android.intent.action.PROCESS_TEXT")
                   E: data (line=27)
                     A: android:mimeType(0x01010026)="text/plain" (Raw: "text/plain")
               E: application (line=31)
                 A: android:label(0x01010001)="fix" (Raw: "fix")
                 A: android:icon(0x01010002)=@0x7f080000
                 A: android:name(0x01010003)="android.app.Application" (Raw: "android.app.Application")
                 A: android:debuggable(0x0101000f)=(type 0x12)0xffffffff
                 A: android:extractNativeLibs(0x010104ea)=(type 0x12)0x0
                 A: android:appComponentFactory(0x0101057a)="androidx.core.app.CoreComponentFactory" (Raw: "androidx.core.app.CoreComponentFactory")
                 E: activity (line=48)
                   A: android:theme(0x01010000)=@0x7f0a0000
                   A: android:name(0x01010003)="com.example.fix.MainActivity" (Raw: "com.example.fix.MainActivity")
                   A: android:exported(0x01010010)=(type 0x12)0xffffffff
                   A: android:launchMode(0x0101001d)=(type 0x10)0x1
                   A: android:configChanges(0x0101001f)=(type 0x11)0x40003fb4
                   A: android:windowSoftInputMode(0x0101022b)=(type 0x11)0x10
                   A: android:hardwareAccelerated(0x010102d3)=(type 0x12)0xffffffff
                   E: meta-data (line=63)
                     A: android:name(0x01010003)="io.flutter.embedding.android.NormalTheme" (Raw: "io.flutter.embedding.android.NormalTheme")
                     A: android:resource(0x01010025)=@0x7f0a0001
                   E: intent-filter (line=67)
                     E: action (line=68)
                       A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")
                     E: category (line=70)
                       A: android:name(0x01010003)="android.intent.category.LAUNCHER" (Raw: "android.intent.category.LAUNCHER")
                 E: meta-data (line=77)
                   A: android:name(0x01010003)="flutterEmbedding" (Raw: "flutterEmbedding")
                   A: android:value(0x01010024)=(type 0x10)0x2
                 E: uses-library (line=81)
                   A: android:name(0x01010003)="androidx.window.extensions" (Raw: "androidx.window.extensions")
                   A: android:required(0x0101028e)=(type 0x12)0x0
                 E: uses-library (line=84)
                   A: android:name(0x01010003)="androidx.window.sidecar" (Raw: "androidx.window.sidecar")
                   A: android:required(0x0101028e)=(type 0x12)0x0
[   +6 ms] Stopping app 'app-debug.apk' on sdk gphone64 x86 64.
executing: C:\Users\HZB\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell am force-stop com.example.fix
[ +195 ms] executing: C:\Users\HZB\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell pm list packages com.example.fix
[ +164 ms] package:com.example.fix
[   +1 ms] executing: C:\Users\HZB\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell cat /data/local/tmp/sky.com.example.fix.sha1
[ +137 ms] 0bb06d93f61831a1fce2e3a05ed3836a288163ab
[   +1 ms] Latest build already installed.
[        ] executing: C:\Users\HZB\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell -x logcat -v time -t 1
[  +98 ms] --------- beginning of main
           05-08 09:45:08.955 W/InputManager-JNI(  583): Input channel object '78305af Splash Screen com.example.fix (client)' was disposed without first being removed with the input manager!
[  +10 ms] executing: C:\Users\HZB\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x20000000 --ez enable-dart-profiling true --ez enable-checked-mode true
--ez verify-entry-points true com.example.fix/com.example.fix.MainActivity
[ +122 ms] Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x20000000 cmp=com.example.fix/.MainActivity (has extras) }
[        ] Waiting for VM Service port to be available...
[ +695 ms] VM Service URL on device: http://127.0.0.1:35685/6udoWFuejRk=/
[   +1 ms] executing: C:\Users\HZB\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 forward tcp:0 tcp:35685
[  +69 ms] 29660
[        ] Forwarded host port 29660 to device port 35685 for VM Service
[   +4 ms] Caching compiled dill
[ +163 ms] Connecting to service protocol: http://127.0.0.1:29660/6udoWFuejRk=/
[ +361 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:29660/6udoWFuejRk=/.
[ +238 ms] E/flutter ( 5473): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
[        ] E/flutter ( 5473): 
[ +111 ms] DDS is listening at http://127.0.0.1:29687/OUzyjYwOVUw=/.
[  +80 ms] Successfully connected to service protocol: http://127.0.0.1:29660/6udoWFuejRk=/
[  +74 ms] DevFS: Creating new filesystem on the device (null)
[  +50 ms] DevFS: Created new filesystem on the device (file:///data/user/0/com.example.fix/code_cache/fixXDYACM/fix/)
[   +3 ms] Updating assets
[ +139 ms] Syncing files to device sdk gphone64 x86 64...
[   +2 ms] Compiling dart to kernel with 0 updated files
[        ] Processing bundle.
[        ] <- recompile package:fix/main.dart ad977d79-3c27-4f94-99a6-d17554b79bc0
[        ] <- ad977d79-3c27-4f94-99a6-d17554b79bc0
[   +2 ms] Bundle processing done.
[  +99 ms] Updating files.
[        ] DevFS: Sync finished
[   +1 ms] Syncing files to device sdk gphone64 x86 64... (completed in 107ms)
[        ] Synced 0.0MB.
[   +1 ms] <- accept
[  +14 ms] Connected to _flutterView/0x70c37dbdaee0.

The exception always occurs after building .apk. Then the app will hang and not open on Android.

TabooSun commented 1 week ago

I believe this is caused by my reported bug #352

knopp commented 1 week ago

This indeed looks like a duplicate of https://github.com/superlistapp/super_native_extensions/issues/352. I'll see if I can reproduce this. Could be a change in recent Rust.

EMUNES commented 1 week ago

This problem occurs after we upgrade flutter to 3.19.6 and rust from 1.77 to 1.78. So yes, it could be a rust problem instead.

knopp commented 1 week ago

Thanks for confirmation. There does seem to be a change of behavior where 1.78 links eh_personality for unoptimized no-std build for some reason. This should be fixed by https://github.com/irondash/irondash/pull/51.

EMUNES commented 1 week ago

Not waiting for merging, I have cloned irondash repo and tried this fix locally. The exception is finally gone, and the app runs normally on Android devices.

Thanks for working on this! Feel free to close this issue, after the fix is merged or not.