Flutter iOS端Check failed: factories_.count(idString) == 0错误求助
解决Flutter iOS端运行时的[VERBOSE-3:FlutterPlatformViews.mm(239)]错误
问题说明
在Xcode中运行Flutter项目时触发以下错误:
[VERBOSE-3:FlutterPlatformViews.mm(239)] Check failed: factories_.count(idString) == 0
错误定位至FLTWebViewFlutterPlugin的registerWithRegistrar方法。已执行flutter clean、flutter pub get、pod install操作,但问题仍未解决。
可能的解决方案
排查WebView插件重复注册
该错误核心原因是同一个Platform View ID被多次注册(此处为plugins.flutter.io/webview)。检查pubspec.yaml文件,确认没有同时引入多个WebView相关插件(例如webview_flutter和flutter_webview_plugin),保留其中一个即可。彻底清理iOS端构建缓存
- 执行
flutter clean清除Flutter缓存 - 进入iOS目录,删除
Pods文件夹、Podfile.lock和Runner.xcworkspace文件 - 在iOS目录下运行
pod deintegrate彻底卸载所有Pods依赖 - 返回项目根目录,重新执行
flutter pub get和cd ios && pod install - 重启Xcode,按下
Cmd+Shift+K清理Xcode缓存后重新运行项目
- 执行
验证插件与Flutter版本兼容性
确保webview_flutter插件版本与当前Flutter SDK版本匹配。若使用Flutter 3.x及以上版本,建议升级webview_flutter至4.x及以上版本;若使用旧版Flutter,选择对应兼容的插件版本。检查自定义插件源码
若你修改过FLTWebViewFlutterPlugin的源码,确认没有重复调用registerViewFactory方法,且项目中没有其他代码注册plugins.flutter.io/webview这个ID。
相关代码与日志
FLTWebViewFlutterPlugin源码
// Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #import "FLTWebViewFlutterPlugin.h" #import "FLTCookieManager.h" #import "FlutterWebView.h" @implementation FLTWebViewFlutterPlugin + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar { FLTWebViewFactory* webviewFactory = [[FLTWebViewFactory alloc] initWithMessenger:registrar.messenger]; [registrar registerViewFactory:webviewFactory withId:@"plugins.flutter.io/webview"]; [FLTCookieManager registerWithRegistrar:registrar]; } @end
运行日志
2022-11-07 16:32:18.912377+0800 Runner[51398:324228] Metal API Validation Enabled. 2022-11-07 16:32:19.150893+0800 Runner[51398:324228] [VERBOSE-3:FlutterPlatformViews.mm(239)] Check failed: factories_.count(idString) == 0. CoreSimulator 857.7 - Device: iPhone 14 Pro (A307DF5E-C1CA-4F0D-8188-9C52CCA79B51) - Runtime: iOS 16.0 (20A360) - DeviceType: iPhone 14 Pro. (lldb).
内容的提问来源于stack exchange,提问作者Afiq Harith
相关产品推荐
相关产品推荐

