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

PodSpec验证报错:vendored_frameworks路径匹配失败及模块找不到

关于包含xcframework的Pod库spec验证失败的问题

问题背景

我有一个包含xcframework的Pod库,其podspec定义如下:

Pod::Spec.new do |s|
  s.name                  = 'MySDK'
  s.version               = '1.0.0'
  s.summary               = 'Summary'
  s.description           = 'Description'
  s.homepage              = 'homepage_url'
  s.license               = { :type => 'MIT', :file => 'LICENSE' }
  s.author                = { 'xxxxx' => 'xxxxxx' }
  s.source                = { :git => 'xxxxxx' }
  s.ios.deployment_target = '15.0'

  s.source_files          = 'MySDK/**/*.{swift,xcframework}''
  s.vendored_frameworks   = 'MySDK/Frameworks/MyFramework.xcframework'
  s.preserve_paths       = 'MySDK/Frameworks/MyFramework.xcframework'
  s.xcconfig              = { 'OTHER_LDFLAGS' => '-framework MyFramework' }
  s.frameworks            = 'UIKit', 'SwiftUI', 'XCTest', 'MyFramework'
  
  s.dependency 'iOSDFULibrary', '~> 4.13.0'

end

使用pod lib lint --allow-warnings --no-clean验证时结果正常:MySDK passed validation.

但使用pod spec lint验证时出现如下错误:

-> MySDK (1.0.0)
    - ERROR | file patterns: The `preserve_paths` pattern did not match any file.
    - ERROR | [iOS] file patterns: The `vendored_frameworks` pattern did not match any file.
    - WARN  | [iOS] license: Unable to find a license file
    - WARN  | [iOS] swift: The validator used Swift `4.0` by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_versions` attribute in your podspec. Note that usage of a `.swift-version` file is now deprecated.
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Building targets in dependency order
    - NOTE  | [iOS] xcodebuild:  Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 9.0, but the range of supported deployment target versions is 11.0 to 16.2.99. (in target 'iOSDFULibrary' from project 'Pods')
    - NOTE  | [iOS] xcodebuild:  Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 9.0, but the range of supported deployment target versions is 11.0 to 16.2.99. (in target 'ZIPFoundation' from project 'Pods')
    - NOTE  | [iOS] xcodebuild:  note: Metadata extraction skipped. No AppIntents.framework dependency found. (in target 'ZIPFoundation' from project 'Pods')
    - ERROR | [iOS] xcodebuild:  MySDK/MySDK/MySDK/Classes/Managers/BluetoothStatusManager.swift:11:8: error: no such module 'MyFramework'
    - NOTE  | [iOS] xcodebuild:  note: Metadata extraction skipped. No AppIntents.framework dependency found. (in target 'iOSDFULibrary' from project 'Pods')

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 4 errors and 2 warnings.

问题分析与解决方案

1. vendored_frameworks和preserve_paths路径匹配失败

pod spec lint会拉取远程git仓库的代码进行验证,而pod lib lint使用本地文件。如果MyFramework.xcframework未提交到git,或者仓库中的实际路径与podspec定义不符,就会触发该错误。

  • 解决措施:
    • 确认MyFramework.xcframework已添加到git提交列表,未被.gitignore排除
    • 核对仓库根目录下是否存在MySDK/Frameworks/MyFramework.xcframework,确保路径完全匹配podspec中的定义

2. 找不到LICENSE文件

  • 解决措施:在仓库根目录添加LICENSE文件,确保文件名与podspec中license字段的file值完全一致,并且已提交到git。

3. Swift版本未指定

  • 解决措施:在podspec中添加swift_versions字段,示例:
    # 指定单个版本
    s.swift_version = '5.7'
    # 或者支持多个版本
    s.swift_versions = ['5.5', '5.6', '5.7']
    

4. no such module 'MyFramework'错误

该错误是xcframework未正确引入的连锁反应,解决完路径匹配问题后会自动消失。额外优化点:

  • 无需在s.frameworks中添加MyFramework,vendored_frameworks会自动处理框架引入
  • 可以删除s.xcconfig中的OTHER_LDFLAGS配置,vendored_frameworks会自动添加必要的链接参数

5. 依赖库部署版本警告

iOSDFULibrary和ZIPFoundation的部署目标低于SDK的15.0,属于警告不影响验证,若要消除:

  • 在podspec中添加配置统一部署目标:
    s.pod_target_xcconfig = { 'IPHONEOS_DEPLOYMENT_TARGET' => '15.0' }
    s.user_target_xcconfig = { 'IPHONEOS_DEPLOYMENT_TARGET' => '15.0' }
    

修改后的podspec示例

Pod::Spec.new do |s|
  s.name                  = 'MySDK'
  s.version               = '1.0.0'
  s.summary               = 'Summary'
  s.description           = 'Description'
  s.homepage              = 'homepage_url'
  s.license               = { :type => 'MIT', :file => 'LICENSE' }
  s.author                = { 'xxxxx' => 'xxxxxx' }
  s.source                = { :git => 'xxxxxx', :tag => s.version.to_s } # 建议添加tag便于版本管理
  s.ios.deployment_target = '15.0'
  s.swift_version         = '5.7' # 指定Swift版本

  s.source_files          = 'MySDK/**/*.swift' # 移除xcframework,由vendored_frameworks单独处理
  s.vendored_frameworks   = 'MySDK/Frameworks/MyFramework.xcframework'
  # 移除preserve_paths,vendored_frameworks已自动处理路径保留
  s.frameworks            = 'UIKit', 'SwiftUI' # 移除XCTest(无需作为依赖框架)和MyFramework
  
  s.dependency 'iOSDFULibrary', '~> 4.13.0'
  # 统一部署目标配置
  s.pod_target_xcconfig = { 'IPHONEOS_DEPLOYMENT_TARGET' => '15.0' }
  s.user_target_xcconfig = { 'IPHONEOS_DEPLOYMENT_TARGET' => '15.0' }
end

验证命令建议

使用以下命令重新验证:

pod spec lint --allow-warnings

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 22:47:14