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

Flutter集成TensorFlowLite时Xcode构建失败求助

Flutter iOS构建失败:'TensorFlowLiteC.h' 文件找不到的解决方案

问题背景

使用tflite:1.1.2插件开发Flutter应用时,iOS模拟器调试出现Xcode构建失败,核心错误为:

fatal error: 'TensorFlowLiteC.h' file not found

手动添加pod 'TensorFlowLiteObjC'到Podfile后问题未解决。

解决方案

1. 升级tflite插件版本

旧版本tflite:1.1.2依赖的TensorFlowLiteC版本存在兼容性问题,建议升级至最新稳定版:

  • 修改pubspec.yaml中的依赖:
    dependencies:
      tflite: ^2.1.0 # 可前往pub.dev确认最新版本
    
  • 执行命令更新依赖:
    flutter pub get
    cd ios && pod install --repo-update
    

2. 调整Podfile配置

  • 打开iOS目录下的Podfile,将平台部署目标设置为11.0及以上:
    platform :ios, '11.0'
    
  • 移除手动添加的pod 'TensorFlowLiteObjC',避免版本冲突。
  • 在post_install块中添加配置,统一TensorFlowLiteC的部署目标:
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
        if target.name == 'TensorFlowLiteC'
          target.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
          end
        end
      end
    end
    

3. 清理构建缓存

执行以下命令彻底清理缓存,避免旧依赖干扰:

flutter clean
rm -rf ios/Pods
rm ios/Podfile.lock
rm -rf ~/Library/Developer/Xcode/DerivedData

清理完成后重新执行:

flutter pub get
cd ios && pod install

4. 验证Xcode构建设置

打开iOS项目的Runner.xcworkspace,选中tflite target,进入Build Settings:

  • 确保Header Search Paths包含$(inherited)和${PODS_ROOT}/TensorFlowLiteC/Headers
  • 确保Library Search Paths包含$(inherited)和${PODS_ROOT}/TensorFlowLiteC

内容的提问来源于stack exchange,提问作者Christian Leyva

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 05:10:28