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

Flutter iOS项目添加Share Extension后pod install遇版本兼容报错

解决Flutter iOS添加Share Extension后pod install报错:CopyArgumentError - [Xcodeproj] Unable to find compatibility version string for object version 70

问题概述

在Flutter iOS项目中添加Share Extension并修改Podfile后,执行pod install时触发以下错误:

CopyArgumentError - [Xcodeproj] Unable to find compatibility version string for object version 70

环境信息

  • CocoaPods: 1.16.2
  • Xcode: 16.1
  • macOS: 15.0.1
  • Flutter项目

涉及Podfile配置

ENV['COCOAPODS_DISABLE_STATS'] = 'true'

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}"
end

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

platform :ios, '13.0'

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

target 'Share Extension' do
  use_frameworks!
  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

复现步骤

  1. 拥有一个已安装Pods的正常运行的Flutter iOS项目
  2. 在Xcode中添加Share Extension目标
  3. 在Podfile中添加该Share Extension目标
  4. 执行pod install -> 触发错误

已尝试的无效方法

  • 删除Pods/、Podfile.lock、Runner.xcworkspace后重新安装
  • 尝试不同的Podfile配置
  • 执行pod deintegrate后重新安装
  • 删除并重新添加Share Extension
  • 降级CocoaPods

解决思路

1. 升级CocoaPods到适配Xcode 16的版本

Xcode 16对应的项目对象版本为70,CocoaPods 1.16.2未适配该版本,直接升级到最新稳定版:

sudo gem install cocoapods

或通过Homebrew升级:

brew upgrade cocoapods

2. 调整Share Extension目标的Podfile配置

Share Extension作为轻量级扩展,不需要完整的Flutter依赖,移除flutter_install_all_ios_pods调用,改为按需引入依赖:

target 'Share Extension' do
  use_frameworks!
  # 继承主项目的Pod搜索路径,避免重复配置
  inherit! :search_paths
  # 仅添加Extension实际需要的Pod,例如:
  # pod 'YourRequiredPod'
end

3. 修改项目兼容性版本

若升级CocoaPods后仍报错,手动调整Xcode项目设置:

  • 打开Runner.xcodeproj,选中Share Extension目标
  • 进入Build Settings,搜索Project Format
  • 将其设置为Xcode 15.0-compatible(对应对象版本66),或与主项目保持一致
  • 重新执行pod install

4. 彻底清理缓存后重试

执行以下命令清理所有缓存文件:

rm -rf ~/Library/Developer/Xcode/DerivedData
pod deintegrate
rm -rf Pods Podfile.lock Runner.xcworkspace
flutter clean
flutter pub get
pod install

内容的提问来源于stack exchange,提问作者Edon Freiner

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 04:27:37