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

问题描述

iOS上的抖动问题 在XCode中,某些库(SharedPreferences,Apple登录显示错误

No type or protocol named 'FlutterPluginRegistrar'

我已经尝试过:清理干净,pod更新,清理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.