执行pod spec lint时遇xcodebuild失败错误的求助
解决Pod Spec Lint中SnapshotTesting的macOS版本兼容错误
问题
执行pod spec lint时报错:xcodebuild: Returned an unsuccessful exit code,确认问题和SnapshotTesting版本相关,但不清楚修复方法。
现有配置
Swift Package配置
let package = Package( name: "PersianJustify", platforms: [.iOS(.v13), .macOS(.v11), .tvOS(.v12)], products: [ .library( name: "PersianJustify", targets: ["PersianJustify"]), ], dependencies: [ .package(url: "https://github.com/ArtSabintsev/FontBlaster", from: "5.3.0"), .package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.15.4"), ], targets: [ .target( name: "PersianJustify"), .testTarget( name: "PersianJustifyTests", dependencies: [ "PersianJustify", "FontBlaster", .product(name: "SnapshotTesting", package: "swift-snapshot-testing"), ], exclude: ["SnapshotTests/__Snapshots__"], resources: [.process("Resources")] ), ] )
Podspec配置
Pod::Spec.new do |s| s.name = 'PersianJustify' s.version = '0.6.1' s.summary = 'Justify Persian / Arabic / Hebrew languages texts from the right!' s.description = 'Not very efficient way to justify Hebrew languages in iOS using the Swift language and CoreText.' s.homepage = 'https://github.com/HappyIosDeveloper/PersianJustify' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'Ahmadreza' => 'mail.sarafraz@email.com' } s.platform = :ios, '10.0' s.platform = :macos, '11' s.swift_version = '5.0' s.dependency 'FontBlaster' s.dependency 'SnapshotTesting' s.source_files = "Sources/PersianJustify/*.{h,m,swift}" s.source = { :git => 'https://github.com/HappyIosDeveloper/PersianJustify.git', :tag => '0.6.1' } end
错误信息
-> PersianJustify (0.6.1) - ERROR | [OSX] xcodebuild: Returned an unsuccessful exit code. - NOTE | xcodebuild: note: Using codesigning identity override: - NOTE | [OSX] xcodebuild: note: Building targets in dependency order - NOTE | [OSX] xcodebuild: note: Target dependency graph (5 targets) - ERROR | xcodebuild: SnapshotTesting/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift:44:8: error: 'curveTo' is only available in macOS 11.0 or newer - NOTE | xcodebuild: SnapshotTesting/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift:44:8: note: add 'if #available' version check - NOTE | xcodebuild: SnapshotTesting/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift:40:22: note: add @available attribute to enclosing static method - NOTE | xcodebuild: SnapshotTesting/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift:29:1: note: add @available attribute to enclosing extension - ERROR | xcodebuild: SnapshotTesting/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift:51:8: error: 'curveTo' is only available in macOS 11.0 or newer - NOTE | xcodebuild: SnapshotTesting/Sources/SnapshotTesting/Snapshotting/NSBezierPath.swift:51:8: note: add 'if #available' version check - NOTE | [OSX] xcodebuild: Pods.xcodeproj: warning: The macOS deployment target 'MACOSX_DEPLOYMENT_TARGET' is set to 10.10, but the range of supported deployment target versions is 10.13 to 14.4.99. (in target 'FontBlaster' from project 'Pods') - NOTE | [OSX] xcodebuild: Pods.xcodeproj: warning: The macOS deployment target 'MACOSX_DEPLOYMENT_TARGET' is set to 10.10, but the range of supported deployment target versions is 10.13 to 14.4.99. (in target 'SnapshotTesting' from project 'Pods')
修复方案
从错误信息能看出两个核心问题:
- SnapshotTesting代码使用了macOS 11.0才有的
curveTo方法,但CocoaPods构建时把依赖的部署目标降到了10.10,导致编译失败。 - Podspec虽指定了macOS最低版本为11,但未强制传递该版本给依赖库。
步骤1:修改Podspec,强制依赖库使用正确部署目标
在Podspec中添加配置,强制所有依赖的macOS部署目标与你的库保持一致:
s.dependency 'FontBlaster', '>= 5.3.0' s.dependency 'SnapshotTesting', '>= 1.15.4' # 添加以下代码覆盖依赖的部署目标 s.pod_target_xcconfig = { 'MACOSX_DEPLOYMENT_TARGET' => '11.0' } s.user_target_xcconfig = { 'MACOSX_DEPLOYMENT_TARGET' => '11.0' }
步骤2:可选——指定测试平台
如果你的主要发布平台是iOS,可以临时限定lint仅测试iOS平台,跳过macOS的兼容性检查:
pod spec lint --platforms=ios
步骤3:验证修复
修改后重新执行pod spec lint,若仍有问题,清理CocoaPods缓存后重试:
pod cache clean --all
内容的提问来源于stack exchange,提问作者Ahmadreza
相关产品推荐
相关产品推荐

