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

LateInitializationError on Windows. After updating to Flutter 3.10 and Dart 3.0.0 #91

Open
DixomDIY opened this issue May 14, 2023 · 8 comments

Comments

@DixomDIY
Copy link

DixomDIY commented May 14, 2023

• Flutter version 3.10.0 on channel stable at D:\Flutter
• Framework revision 84a1e904f4 (5 days ago), 2023-05-09 07:41:44 -0700
• Engine revision d44b5a94c9
• Dart version 3.0.0
• DevTools version 2.23.1

I'm using flutter stable channel, recently updated to Flutter 3.10 and Dart 3.0.0. Now the QuickUsb library does not work. After calling var init = await QuickUsb.init(); a LateError occurs (LateInitializationError: field '_instance@326265524' was not initialized).

This happens on the Windows 11 platform, everything is fine on Android. Not tested on other platforms. I tried to clear the cache in .dart_tool, it did not help.

@DixomDIY
Copy link
Author

I tried using a later version of quick_usb 0.3.1. And no problems, everything works.

@mpl
Copy link

mpl commented May 25, 2023

I can confirm that I see the same symptoms for 0.4.0 , but on macOS (Dart 3.0.1).
And that forcing the version to 0.3.1 indeed allows avoiding the error.

@AliJavdani91
Copy link

same issue

[√] Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22621.1848], locale en-CA)
[√] 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 for Windows (Visual Studio Community 2022 17.6.4)
[√] Android Studio (version 2022.2)
[√] Connected device (4 available)
[√] Network resources

@developerLEM
Copy link

same issue:

Android Studio 2021.3
Flutter 3.10.0 (Dart 3.0.0)
Android SDK 33.0.0 (Java 11.0.13+)
(Xcode 14.3)

Trying with lib version 0.4.0 error log is:

Building macOS application...
2023-06-22 16:08:47.497 xcodebuild[13461:689947] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00008103-000E61043C62001E }
{ platform:macOS, arch:x86_64, id:00008103-000E61043C62001E }
Debug service listening on ws://127.0.0.1:55901/XNSQgabXg3A=/ws
Syncing files to device macOS...
2023-06-22 16:09:01.229 flutter_usb[13596:690430] Warning: Window move completed without beginning
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: LateInitializationError: Field '_instance@28265524' has not been initialized.
#0 QuickUsbPlatform._instance (package:quick_usb/src/quick_usb_platform_interface.dart)
#1 QuickUsbPlatform.instance (package:quick_usb/src/quick_usb_platform_interface.dart:16:43)
#2 _platform (package:quick_usb/quick_usb.dart:10:52)
#3 QuickUsb.init (package:quick_usb/quick_usb.dart:13:33)
#4 _MyHomePageState._init_exit_modified. (package:flutter_usb/main.dart:195:41)
#5 _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1154:21)
#6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:275:24)
#7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:654:11)
.......

Trying with lib version 0.3.1 error log is:

Syncing files to device macOS...
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libusb-1.0.23.dylib': dlopen(libusb-1.0.23.dylib, 0x0001): tried: 'libusb-1.0.23.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibusb-1.0.23.dylib' (no such file), '.../Flutter_usb.app/Contents/Frameworks/FlutterMacOS.framework/Versions/A/./libusb-1.0.23.dylib' (no such file), '.../Flutter_usb/build/macos/Build/Products/Debug/flutter_usb.app/Contents/Frameworks/FlutterMacOS.framework/Versions/A/../../../libusb-1.0.23.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/usr/lib/swift/libusb-1.0.23.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libusb-1.0.23.dylib' (no such file), '/usr/lib/swift/libusb-1.0.23.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libusb-1.0.23.dylib' (no such file), '..../flutter_usb.app/Contents/Frameworks/libusb-1.0.23.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '..../flutter_usb.app/Contents/MacOS/Frameworks/libusb-1.0.23.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libusb-1.0.23.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libusb-1.0.23.dylib' (no such file), '.../Flutter_usb/build/macos/Build/Products/Debug/flutter_usb.app/Contents/Frameworks/libusb-1.0.23.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/usr/lib/libusb-1.0.23.dylib' (no such file, not in dyld cache), 'libusb-1.0.23.dylib' (no such file), '/usr/local/lib/libusb-1.0.23.dylib' (no such file), '/usr/lib/libusb-1.0.23.dylib' (no such file, not in dyld cache)
#0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
#1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
#2 new QuickUsbMacos (package:quick_usb/src/quick_usb_desktop.dart:22:37)
#3 _platform (package:quick_usb/quick_usb.dart:25:35)
#4 QuickUsb.init (package:quick_usb/quick_usb.dart:36:33)
#5 _MyHomePageState._init_exit_modified. (package:flutter_usb/main.dart:195:41)
#6 _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1154:21)
........

@ebapp-dev
Copy link

ebapp-dev commented Aug 24, 2023

Any solution for this problem?
Although it works for 0.3.1, I can't open device on linux.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:quick_usb/src/quick_usb_desktop.dart': Failed assertion: line 118 pos 12: '_devHandle != null': Device not open
quick_usb_desktop.dart:118
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2 _QuickUsbDesktop.getConfiguration
quick_usb_desktop.dart:118
#3 QuickUsb.getConfiguration
quick_usb.dart:54
#4 PrintUsb.doPrint
print_usb.dart:47

@TheAnimatrix
Copy link

TheAnimatrix commented May 8, 2024

Even getting a device list causes my entire app to hang, not sure why. This is 0.3.1 (hangs even with proper future handling)
0.4.0 is a non-starter - same issue.

Any alternatives guys ?

@TheAnimatrix
Copy link

Alright i fixed both the error and my laggy issue

1 -> Check your platform and run QuickUsbWindows.registerWith() before init() if you platform is windows. You have functions for each platform. This should solve the initialization error
2 -> if you find the futures are blocking despite waiting for them asynchronously thats natural, you are running all the USB calls on the main thread with high priority. Throw them in an isolate and you should be fine. You have to register, init and exit while in the isolate, dont forget!

@farajshaikh1
Copy link

farajshaikh1 commented Nov 11, 2024

@TheAnimatrix In which version did you apply these fixes (0.4.0 or 0.3.1)?

On macOS 15.0, I am still receiving the following error (on 0.4.0):

Method:

Future<void> tTest() async {
      await QuickUsbMacos.registerWith(); // Error caused by this line.
      await QuickUsbMacos().init();
      QuickUsbMacos().getDeviceList();
      await QuickUsbMacos().exit();
    }

Error:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libusb-1.0.23.dylib': dlopen(libusb-1.0.23.dylib, 0x0001): tried: 'libusb-1.0.23.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibusb-1.0.23.dylib' (no such file)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants