首页 > 解决方案 > pod install 后 iOS 通用框架编译器版本发生变化

问题描述

我在 iOS(封闭源代码)中遇到了通用框架的问题。

创建通用框架时,它显示* 由 Apple Swift 5.1.2 版 (swiftlang-1100.0.278 clang-1100.0.33.9) 生成 *如果将框架添加到项目中,它可以正常工作

但是在将它上传到 git 并使用 pod 安装后,我收到一个错误Module compiled with Swift 5.0.1 cannot be import by the Swift 5.1.2 compiler

当我检查头文件时,我看到// Generated by Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)

我理解的问题是在上传我的编译器时是Swift 版本 5.1.2,这是正确的,但是在 pod install 之后它以某种方式更改为Swift 版本 5.0.1

为什么会发生这种变化?以及如何确保它不会改变?

播客规范

Pod::Spec.new do |s|
s.platform = :ios, '11.0'
s.name = "xyz"
s.version = '1.0.5'
s.summary = 'xyz - Binaries'
s.description = 'Framework for xyz'
s.homepage = 'https://github.com/xyz/xyz'
s.license = { :type => 'MIT' }
s.author = 'https://github.com/Albinzr'
s.requires_arc = true
s.swift_version = '5.1'
s.source = { :http => 'https://github.com/xyz/SDK/blob/master/xyz.framework.zip?raw=true' }
s.ios.deployment_target = '11.0'
s.ios.vendored_frameworks = 'xyz.framework'
end

标签: iosswiftcocoapodsios-universal-framework

解决方案


您会看到这个问题是因为该框架是为与 Xcode 11.0(使用 Swift 5.0)一起分发而构建的。你使用 Xcode 11.2 在本地构建它,它更新了 Swift 5.1.2。Swift 5.1.2 与 5.0 不兼容,但似乎即将发布的 Swift 版本将与 5.0 兼容。因为他们最终在 5.1.2 中引入了Swift Module 稳定性。

确保 CI/CD(或其他分发系统)运行最新的 Xcode。

并确保使用pod install --repo-update. 默认情况下,Cocoapods 不会更新 repo(因为在历史上,在引入CDN之前该过程曾经很慢)

我希望这会有所帮助!


推荐阅读