模块'flutter_barcode_scanner'未找到[Flutter / iOS]

2admgd59  于 2023-04-07  发布在  Flutter
关注(0)|答案(1)|浏览(172)

一段时间后,我试图在iOS设备上运行Flutter应用程序,但该项目无法为iOS构建。
我得到的错误发生在“GeneratedPluginRegistrant.h”文件中,如下所示:

#import "GeneratedPluginRegistrant.h"

#if __has_include(<flutter_barcode_scanner/SwiftFlutterBarcodeScannerPlugin.h>)
#import <flutter_barcode_scanner/SwiftFlutterBarcodeScannerPlugin.h>
#else
@import flutter_barcode_scanner; /* ERROR: Module 'flutter_barcode_scanner' not found */
#endif

我的pubspec.yaml内容如下:

name: test_app
description: A new Flutter project.

publish_to: "none" # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.17.6 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  
  flutter_speed_dial: ^6.2.0
  flutter_barcode_scanner: ^2.0.0

flutter_icons:
  android: "launcher_icon"
  ios: true
  image_path: "assets/playstore_icon.png"
  min_sdk_android: 29

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: ^0.10.0

  flutter_lints: ^2.0.0

flutter:
  uses-material-design: true

  assets:
    - assets/
    - assets/illustrations/

我的Flutter没有问题,由flutter doctorcommand 输出如下:

[✓] Flutter (Channel stable, 3.3.8, on macOS 12.6 21G115 darwin-arm, locale
    en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.74.3)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

为了解决这个问题,我首先尝试了以下命令:

flutter clean
flutter pub get

但是问题仍然存在。然后我使用以下步骤解决了问题:
步骤1:删除项目中的iOS文件夹。
第2步:使用终端中的命令如下-

flutter create -i swift .
flutter clean
flutter pub get

问题仍然存在,构建失败,并出现与上述相同的错误。
现在不太确定如何解决这个问题。有人能帮忙吗?
先谢谢你了!

7kqas0il

7kqas0il1#

对我来说,这个答案很有帮助:https://stackoverflow.com/a/68299585/20274645
运行后:

      • ios**文件夹中的pod install
  • flutter build ios
  • 对于“flutter_barcode_scanner”包,一般注意ios部署目标至少要设置为12,Swift版本至少要设置为5*

相关问题