Apple Silicon Mac上Flutter报错:Module 'shared_preferences_ios' not found
用Rosetta运行终端执行命令
Apple Silicon终端默认arm64架构,部分插件依赖可能存在兼容问题。右键终端图标选「显示简介」,勾选「使用Rosetta打开」,然后依次执行:flutter clean rm -rf ios/Pods ios/Podfile.lock ios/Runner.xcworkspace flutter pub get cd ios && pod install修改Podfile添加架构兼容配置
打开ios/Podfile,在post_install代码块中补充架构设置:post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) # 新增以下配置 target.build_configurations.each do |config| config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64' end end end保存后重新执行
cd ios && pod install,再打开Xcode workspace运行项目。清除Flutter插件本地缓存
清理pub缓存里的shared_preferences相关文件,重新拉取依赖:flutter clean rm -rf ~/.pub-cache/hosted/pub.dartlang.org/shared_preferences* flutter pub get cd ios && pod repo update && pod install检查Xcode的架构设置
打开Xcode workspace,选中Runner target,进入「Build Settings」:- 找到「Architectures」,设置为「Standard Architectures (arm64, x86_64)」
- 找到「Excluded Architectures」,确保Debug/Release模式下没有误排除arm64或x86_64(模拟器运行时需保留x86_64)
指定shared_preferences稳定版本
最新版本可能存在兼容bug,在pubspec.yaml里指定一个经过验证的稳定版本:dependencies: flutter: sdk: flutter shared_preferences: ^2.2.2执行
flutter pub get和cd ios && pod install后再尝试运行。
内容的提问来源于stack exchange,提问作者s3v3ns
相关产品推荐
相关产品推荐

