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

Flutter tflite_flutter在iOS Debug正常,Release模式模型加载失败

iOS Release模式下TFLite GPU Delegate加载失败的解决方案

针对你遇到的Debug模式正常、Release模式报错Failed to lookup symbol 'TFLGpuDelegateCreate'的问题,以下是几个可行的解决办法:

1. 关闭Dead Code Stripping

iOS Release模式默认会开启无用代码剥离,可能把GPU delegate的核心符号误判为无用代码移除:

  • 打开iOS项目的Xcode工程(ios/Runner.xcworkspace)
  • 在Build Settings里搜索Dead Code Stripping
  • 将Release模式下的该选项设置为NO

2. 强制保留指定符号

如果不想完全关闭代码剥离,可以通过链接器参数强制保留目标符号:

  • 在Xcode Build Settings的Linking分类下,找到Other Linker Flags
  • 添加参数:-u _TFLGpuDelegateCreate

3. 确认Pod依赖配置

确保TensorFlow Lite GPU相关依赖在Release模式下正确引入:

  • 打开ios/Podfile,确认插件已正确引入GPU delegate相关依赖(Flutter的tflite插件通常会自动处理,但可手动检查)
  • 执行pod install --repo-update更新依赖

4. 升级TFLite插件版本

旧版本的tflite插件可能存在iOS Release模式的兼容性问题:

  • 修改pubspec.yaml中的tflite依赖为最新稳定版
  • 执行flutter pub get后重新编译iOS项目

5. 临时切换到CPU delegate

如果上述方法都无效,可以针对iOS Release模式 fallback 到CPU delegate,保证应用正常运行:

Future loadModel() async {
  final options = InterpreterOptions();
  tempDir = await getApplicationDocumentsDirectory();

  print("load");
  try {
    // iOS Release模式不启用GPU delegate
    if (!(Platform.isIOS && kReleaseMode)) {
      options.addDelegate(GpuDelegate());
    }
    interpreter = await tfl.Interpreter.fromAsset('mobilefacenet.tflite',
        options: options);
    setState(() {
      faceModel = "loaded successfully";
    });
  } on Exception {
    setState(() {
      faceModel = "failed to load";
    });
    print('Failed to load model.');
  }
}

内容的提问来源于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.20 18:40:13