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

Xcode 16.2编译报错:GTMSessionFetcher类重复定义求助

解决Xcode 16.2中Flutter应用GTMSessionFetcher重复定义编译错误

问题根源

你的项目依赖中同时引入了GTMSessionFetcher/Core和GTMSessionFetcher/Full两个子spec版本,Core是Full的子集,导致类、枚举等符号重复定义,触发编译链接错误。

具体解决步骤

1. 强制统一GTMSessionFetcher依赖类型

在项目的ios/Podfile中修改post_install钩子,强制所有依赖使用同一个子spec(推荐用Full版本覆盖Core),同时锁定版本避免差异:

post_install do |installer|
  flutter_additional_ios_build_settings(installer)
  
  # 替换所有Core子spec为Full
  installer.pods_project.targets.each do |target|
    target.dependencies.each do |dep|
      if dep.name == 'GTMSessionFetcher' && dep.spec_name == 'Core'
        dep.spec_name = 'Full'
      end
    end
  end

  # 统一锁定GTMSessionFetcher版本(替换为当前兼容的稳定版)
  installer.pod_targets.each do |target|
    if target.name == 'GTMSessionFetcher'
      target.version = '2.3.0'
    end
  end
end

2. 彻底清理缓存并重装依赖

执行以下命令清理所有相关缓存,避免残留冲突文件:

flutter clean
rm -rf ios/Pods ios/Podfile.lock
rm -rf ~/Library/Caches/CocoaPods
rm -rf ios/build
pod repo update
cd ios && pod install

3. 手动检查并移除重复依赖(可选)

打开Xcode进入项目的Pods目录,确认是否同时存在GTMSessionFetcher和GTMSessionFetcherCore目标,若有则右键删除GTMSessionFetcherCore;同时检查pubspec.yaml中的Flutter依赖,尝试升级可能引入冲突的第三方包。

4. 重新编译验证

执行flutter run或在Xcode中点击构建按钮,确认重复定义错误是否消失。

附相关文件示例

编译错误信息

duplicate symbol 'OBJC_CLASS$_GTMSessionFetcherUserDefaultsFactory' in:
/Users/xxx/Library/Developer/Xcode/DerivedData/Runner-xxx/Build/Products/Debug-iphonesimulator/GTMSessionFetcher/GTMSessionFetcher.framework/GTMSessionFetcher(GTMSessionFetcherUserDefaultsFactory.o)
/Users/xxx/Library/Developer/Xcode/DerivedData/Runner-xxx/Build/Products/Debug-iphonesimulator/GTMSessionFetcherCore/GTMSessionFetcherCore.framework/GTMSessionFetcherCore(GTMSessionFetcherUserDefaultsFactory.o)
duplicate symbol 'OBJC_METACLASS$_GTMSessionFetcherUserDefaultsFactory' in:
...
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Podfile示例

platform :ios, '14.0'
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  flutter_additional_ios_build_settings(installer)
end

Podfile.lock相关片段

PODS:
  ...
  - GTMSessionFetcher/Core (2.2.0):
    - GTMSessionFetcher/Full (= 2.2.0)
  - GTMSessionFetcher/Full (2.2.0)
  ...
DEPENDENCIES:
  ...
  - GTMSessionFetcher/Core (from `https://github.com/google/gtm-session-fetcher.git`, tag `v2.2.0`)
  - GTMSessionFetcher/Full (from `https://github.com/google/gtm-session-fetcher.git`, tag `v2.2.0`)
  ...

内容的提问来源于stack exchange,提问作者Denise Schindelböck

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 19:37:16