Xcode13打包到苹果,会被自动改版本号的问题

2,157 阅读2分钟

现象

首先代码明确改了版本号如下:

image.png

结果上传到苹果自动变成了

image.png

排查结果

经过排查,问题出在Xcode13的一个打包Archives导出的新配置上面。

image.png

网上也有人同样遇到这个问题

stackoverflow.com/questions/6…

developer.apple.com/forums/thre…

而且苹果不单改了我们的主app的版本号,还把里面的第三方的framework的版本号也改。 超级变态。看苹果xcode13的更新说明

Automatic version number management is `new` to Xcode `13`. 
These additions were detailed in a WWDC session, as well as the Xcode ``13` `Release Notes:` 
`When uploading an app to App Store Connect, the distribution assistant in Xcode detects whether your app has a valid build number (CFBundleVersion). 
If your app has an invalid number (like one that was used previously, or precedes your current build number), 
the distribution assistant provides an option to automatically increment it to a valid number. In addition, 
the distribution assistant ensures that the build numbers of all embedded content in your app (such as app extensions, 
App Clips, or watchOS apps) are in sync with your app. Note that ``this` `doesn’t modify your source code or your archive; 
Xcode updates the build number in a staged copy of your app before packaging and uploading it to App Store Connect. (``59826409``)`  

`当将应用上传至app Store Connect时,Xcode中的分发助手会检测你的应用是否有一个有效的构建号(CFBundleVersion)。`
`如果你的应用程序有一个无效的数字(如以前使用的,或在当前构建号之前),分发助手提供一个选项,自动增加它到一个有效的数字。`
`此外,分发助手确保所有嵌入在你的应用程序(如应用扩展,应用剪辑,或watchOS应用程序)的构建数字与你的应用程序同步。`
`注意,这不会修改你的源代码或存档;Xcode会在你的应用打包并上传至app Store Connect之前,
在你的应用的分阶段拷贝中更新构建号。(``59826409``)`

解决方法

手动导出

本质上是由于导出App Store签名包的时候,Xcode13多了这个 Manage Version and Bulid Number 选项,因此将这个选项去掉就行了

image.png

使用Fastlane自动打包

在打包编译的方法加上 exportOptions参数,并且将 manageAppVersionAndBuildNumber 设置为 false

image.png