You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apple Silicon Mac上Flutter报错:Module 'shared_preferences_ios' not found

解决Apple Silicon Mac上Flutter shared_preferences_ios模块缺失问题
  • 用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 10:45:34