ios - 没有名为 'FlutterPluginRegistrar' 的类型或协议(protocol)

标签 ios xcode flutter dart cocoapods

ios 上的 Flutter 问题 在 XCode 中,某些库(SharedPreferences、Apple Sign-In)显示错误:

没有名为“FlutterPluginRegistrar”的类型或协议(protocol)

我已经尝试过:flutter clean,pod update,我清理了 pub-cache 并重新安装了所有库,我唯一没有做的就是删除 ios 项目的 pod 文件夹(我做了一次,然后我可以不恢复项目)

screenshot


** BUILD FAILED **


Xcode's output:
↳
  Command CompileSwift failed with a nonzero exit code
  Command CompileSwift failed with a nonzero exit code
  In file included from
  /Users/zippyttech/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.10/ios/Classes/FLTSharedPreferencesPlugin.m:5
  :
  /Users/zippyttech/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.10/ios/Classes/FLTSharedPreferencesPlugin.h:7
  :51: error: no type or protocol named 'FlutterPlugin'
  @interface FLTSharedPreferencesPlugin : NSObject <FlutterPlugin>
                                                    ^
  /Users/zippyttech/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.10/ios/Classes/FLTSharedPreferencesPlugin.m:1
  1:41: error: no type or protocol named 'FlutterPluginRegistrar'
  + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
                                          ^
  /Users/zippyttech/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.10/ios/Classes/FLTSharedPreferencesPlugin.m:1
  2:3: error: use of undeclared identifier 'FlutterMethodChannel'
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME
    ^
  /Users/zippyttech/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.10/ios/Classes/FLTSharedPreferencesPlugin.m:1
  2:25: error: use of undeclared identifier 'channel'
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME
                          ^
  /Users/zippyttech/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.10/ios/Classes/FLTSharedPreferencesPlugin.m:1
  2:36: error: use of undeclared identifier 'FlutterMethodChannel'
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME
                                     ^
  /Users/zippyttech/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.10/ios/Classes/FLTSharedPreferencesPlugin.m:1
  4:4: error: use of undeclared identifier 'channel'
    [channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
     ^
  6 errors generated.
  note: Using new build system
  note: Building targets in parallel
  note: Planning build
  note: Constructing build description

Encountered error while building for device.```

Flutter Version: Flutter 1.20.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 216dee60c0 (10 days ago) • 2020-09-01 12:24:47 -0700
Engine • revision d1bc06f032
Tools • Dart 2.9.2

apple_sign_in: ^0.1.0

shared_preferences: ^0.5.10

最佳答案

我已经为此苦苦挣扎了一段时间,并且我从 here 中找到了 eleomilagrosa 的解决方案。作品:

I found out that the ios/Flutter/Flutter.framework got corrupted the files were all empty or blank.

to fix it,just copy existing ios/Flutter/Flutter.framework from other working Flutter projects you have.
then overwrite the corrupted ios/Flutter/Flutter.framework then build again

Reason:
Flutter.framework got corrupted.

How to identify if your Flutter.framework got corrupted?

open ios/Flutter/Flutter.framework/Headers/Flutter.h if this file is empty or blank.

关于ios - 没有名为 'FlutterPluginRegistrar' 的类型或协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63854708/

相关文章:

firebase - PluginRegistry无法转换为FlutterEngine

ios - index 0 beyond bounds for empty array' *** First throw call stack :

ios - 带Spritekit的Swift-带旋钮的操纵杆教程

xcode - Xcode 10意外的重复任务:CopyPlistFile

ios - 将文本字段中的数字与文本字段中的其他数字相加

firebase - Flutter 从流中获取正确的值

ios - 如何从 JSON 获取特定值并将其元素显示在 CollectionView 上?

ios - 一旦与 Xcode 断开连接,应用程序将无法运行

xcode - 在 Jenkins 中运行 XCodeBuild 的代码签名错误

bluetooth - 用 Flutter 控制 Arduino