kakzaki / blue_thermal_printer

Working with thermal printer via bluetooth (Flutter)
MIT License
164 stars 205 forks source link

flutter analyze fails on v1.1.8 #102

Closed gbloggs closed 2 years ago

gbloggs commented 2 years ago

After upgrading to v1.1.8 and running analyze, the analyze is failing with the following error:

flutter analyze
Analyzing my-flutter...

  error - Target of URI doesn't exist: 'package:blue_thermal_printer/' - lib\generated_plugin_registrant.dart:8:8 - uri_does_not_exist
  error - Undefined name 'BlueThermalPrinterPlugin' - lib\generated_plugin_registrant.dart:25:3 - undefined_identifier
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.5.1, on Microsoft Windows [Version 10.0.19043.1266], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 2020.3)
[√] Connected device (3 available)

• No issues found!

I'm not sure what this file does but seems very web related:

The generated file looks like this:

//
// Generated file. Do not edit.
//

// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars

import 'package:blue_thermal_printer/';
import 'package:firebase_auth_web/firebase_auth_web.dart';
import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:firebase_messaging_web/firebase_messaging_web.dart';
import 'package:fluttertoast/fluttertoast_web.dart';
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
import 'package:image_picker_for_web/image_picker_for_web.dart';
import 'package:package_info_plus_web/package_info_plus_web.dart';
import 'package:shared_preferences_web/shared_preferences_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:video_player_web/video_player_web.dart';
import 'package:wakelock_web/wakelock_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
  BlueThermalPrinterPlugin.registerWith(registrar);
  FirebaseAuthWeb.registerWith(registrar);
  FirebaseCoreWeb.registerWith(registrar);
  FirebaseMessagingWeb.registerWith(registrar);
  FluttertoastWebPlugin.registerWith(registrar);
  GoogleMapsPlugin.registerWith(registrar);
  ImagePickerPlugin.registerWith(registrar);
  PackageInfoPlugin.registerWith(registrar);
  SharedPreferencesPlugin.registerWith(registrar);
  UrlLauncherPlugin.registerWith(registrar);
  VideoPlayerPlugin.registerWith(registrar);
  WakelockWeb.registerWith(registrar);
  registrar.registerMessageHandler();
}
uaandrei commented 2 years ago

you can try and exclude generated_plugin_registrant.dart from analysis, this worked fine for me.

just add in project root a file named analysis_options.yaml with the following content:

analyzer:
  exclude: [lib/generated_plugin_registrant.dart]

reference: https://betterprogramming.pub/dont-panic-when-flutter-generates-a-bad-file-for-you-e5e314c2b01

gbloggs commented 2 years ago

Hi... That makes sense, and has meant the the analyze passed. Is there a way to tell the build not to include this plugin? We use many more plugings, but it seems to have only included ones that have an _web component, which this bluetooth printer one does not. I think I understand why it was failing the analyze, there is no web plugin, but we have used this plugin for a few months now and this has only just happened, from v1.1.8.

Furthermore, whilst adding the exclude allows analyze to pass, building for web fails:

flutter build web

💪 Building with sound null safety 💪

Compiling lib/main.dart for the Web...                          
Target dart2js failed: Exception: lib/generated_plugin_registrant.dart:8:8:
Error: Error when reading '../../../.pub-cache/hosted/pub.dartlang.org/blue_thermal_printer-1.1.8/lib/': Error reading '../../../.pub-cache/hosted/pub.dartlang.org/blue_thermal_printer-1.1.8/lib/'  (Is a directory)
import 'package:blue_thermal_printer/';
       ^
lib/generated_plugin_registrant.dart:25:3:
Error: Getter not found: 'BlueThermalPrinterPlugin'.
  BlueThermalPrinterPlugin.registerWith(registrar);
  ^^^^^^^^^^^^^^^^^^^^^^^^
Error: Compilation failed.
gbloggs commented 2 years ago

I've just updated flutter. The issue remains in 2.5.2 too:

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.5.2, on Microsoft Windows [Version 10.0.19043.1266], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 2020.3)
[√] Connected device (3 available)

• No issues found!
gbloggs commented 2 years ago

Ok. Further to this, iOS builds are failing too for me.

Getting the following build error in Runner/GeneratedPluginRegistrant.m:

//
// Generated file. Do not edit.
//
// clang-format off
#import “GeneratedPluginRegistrant.h”
#if __has_include(<blue_thermal_printer/FlutterBluePlugin.h>)
#import <blue_thermal_printer/FlutterBluePlugin.h>
#else
@import blue_thermal_printer;
#endif
billthecoder046 commented 2 years ago

This issue was even causing me in building the android app as well not letting me to build my web also. I contacted the developer of this package and he upgraded the version from 1.1.9 to 1.2.0 and now everything works fine. Thanks to the developer for his wonderful support.

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.