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

Flutter项目iOS构建报错:'TensorFlowLiteC.h'文件未找到

iOS构建Flutter TFLite项目报错:'TensorFlowLiteC.h' 文件找不到

问题场景

Flutter项目依赖tflite库运行TFLite模型,Android端运行正常,但执行flutter build ios时触发Xcode错误:Lexical or Preprocessor Issue (Xcode): 'TensorFlowLiteC.h' file not found。

解决方案

1. 清理缓存并重新安装依赖

  • 执行flutter clean清理项目缓存
  • 删除iOS目录下的Pods文件夹和Podfile.lock文件
  • 执行flutter pub get重新获取Dart依赖
  • 进入iOS目录:cd ios,执行pod install --repo-update更新Pod仓库并重新安装依赖

2. 调整Podfile配置

  • 检查iOS最低版本,将platform :ios, '11.0'升级为platform :ios, '12.0'(部分TFLite版本要求iOS 12+)
  • 保留use_frameworks! :linkage => :static配置(TFLite静态库需要静态链接)
  • 修改post_install块,添加TFLiteC头文件路径配置:
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
        # 配置TensorFlowLiteC的头文件搜索路径
        if target.name == 'TensorFlowLiteC'
          target.build_configurations.each do |config|
            config.build_settings['HEADER_SEARCH_PATHS'] = '$(inherited) "${PODS_ROOT}/TensorFlowLiteC/Headers"'
          end
        end
      end
    end
    

3. 修正Xcode项目设置

  • 打开iOS目录下的Runner.xcworkspace
  • 选中Runner目标,进入Build Settings选项卡
  • 搜索Header Search Paths,确保包含$(inherited)和${PODS_ROOT}/TensorFlowLiteC/Headers,并设置为Recursive
  • 搜索Library Search Paths,确认包含$(inherited)和${PODS_ROOT}/TensorFlowLiteC

4. 升级tflite库版本

当前使用的tflite: 1.1.2可能存在兼容性问题,尝试升级到最新稳定版本:
在pubspec.yaml中修改依赖:

dependencies:
  tflite: ^1.1.3 # 替换为最新可用版本

之后重新执行flutter pub get和pod install

内容的提问来源于stack exchange,提问作者Am Ventures

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 13:12:43