ios 安装 Xcode 11 后无法在模拟器上运行应用程序 - CFBundleVersion 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56450295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:52:32  来源:igfitidea点击:

Cannot run application on simulator after installing Xcode 11 - CFBundleVersion error

iosxcodexcode10xcode11

提问by Piotr S?kara

Yesterday, I've downloaded beta version of Xcode 11. After that, I've opened my project and tried to run with new Xcode. Unfortunately error has occurred with message:

昨天,我下载了 Xcode 11 的测试版。在那之后,我打开了我的项目并尝试使用新的 Xcode 运行。不幸的是,消息发生了错误:


Failed to install the requested application
Domain: NSPOSIXErrorDomain
Code: 22
Failure Reason: The application's CFBundleVersion is invalid.
Recovery Suggestion: Ensure your bundle contains a CFBundleVersion with a valid semantic version number.
--

I've closed beta version and tried to run again with latest stable version of Xcode (10.2.1), but the same error has occurred. I need to mention that before attempting to run a project with Xocde 11, it worked without any problems on Xcode 10. Nothing has been changed before and after running with beta Xcode.

我已经关闭了测试版并尝试使用最新的稳定版 Xcode (10.2.1) 再次运行,但发生了同样的错误。我需要提到的是,在尝试使用 Xocde 11 运行项目之前,它在 Xcode 10 上运行没有任何问题。在使用 beta Xcode 运行之前和之后没有任何更改。

What I've already tried:

我已经尝试过的:

  • I've removed Xcode 11 beta
  • I've cleaned my project and pulled it from latest branch
  • I've completely removed Xcode 10 from:
  • 我已经删除了 Xcode 11 测试版
  • 我已经清理了我的项目并将其从最新的分支中拉出来
  • 我已经从以下位置完全删除了 Xcode 10:
~/Library/Caches/com.apple.dt.Xcode
~/Library/Developer
~/Library/MobileDevice
~/Library/Preferences/com.apple.dt.Xcode.plist
/Library/Preferences/com.apple.dt.Xcode.plist
/System/Library/Receipts/com.apple.pkg.XcodeExtensionSupport.bom
/System/Library/Receipts/com.apple.pkg.XcodeExtensionSupport.plist
/System/Library/Receipts/com.apple.pkg.XcodeSystemResources.bom
/System/Library/Receipts/com.apple.pkg.XcodeSystemResources.plist
  • And then installed fresh stable version 10.2.1
  • 然后安装了全新的稳定版 10.2.1

I can run other projects which was not tested with Xcode 11 without any problems.

我可以运行其他未经 Xcode 11 测试的项目,没有任何问题。

My last idea is to just reinstall macOS, but I would like to don't do it.

我的最后一个想法是重新安装 macOS,但我不想这样做。

Edit: I've forgot to mention that application is working on physical iPhone XS.

编辑:我忘了提及该应用程序正在物理 iPhone XS 上运行。

采纳答案by Jeremy Huddleston Sequoia

There is a lot of misinformation in the answers here, so I wanted to provide an authoritative response.

这里的答案有很多错误信息,所以我想提供一个权威的回应。

The issue here is that the new version of CoreSimulator.framework with Xcode 11 beta does validation on CFBundleVersion that previous versions did not do. These checks are valid, and it does represent an issue in your application, but there's also a bug in how the checks were performed in Xcode 11 Beta 1 which compounds the issue.

这里的问题是新版本的 CoreSimulator.framework 和 Xcode 11 beta 对 CFBundleVersion 进行了验证,而以前的版本没有这样做。这些检查是有效的,它确实代表了您的应用程序中的一个问题,但在 Xcode 11 Beta 1 中执行检查的方式也存在一个错误,这使问题更加复杂。

First, fix the CFBundleVersion in your Info.plist. It should consist of only numbers and up to two periods (ie ##.[.##[.##]], eg: 12.4.2).

首先,修复 Info.plist 中的 CFBundleVersion。它应该只包含数字和最多两个句点(即##.[.##[.##]],例如:12.4.2)。

Second, after fixing CFBundleVersion, you need to killall -9 CoreSimulatorBridgebecause the old value is unfortunately cached in CoreSimulatorBridge, preventing it from recognizing the new value. This part was a bug, and it was addressed in Xcode 11 Beta 2.

其次,在修复 CFBundleVersion 之后,您需killall -9 CoreSimulatorBridge要这样做,因为不幸的是旧值缓存在 CoreSimulatorBridge 中,阻止它识别新值。这部分是一个错误,在 Xcode 11 Beta 2 中得到了解决。

回答by Cristik

Happened to me too, wasted almost an entire day scouting for possible causes.

我也发生过,几乎浪费了一整天寻找可能的原因。

The steps that finally fixed the problem and allowed me to install on simulator:

最终解决问题并允许我在模拟器上安装的步骤:

  1. Quit Xcode and iOS Simulator
  2. Remove /Library/Developer(the one from root), or rename it if you want to keep a backup
  3. Relaunch Xcode, agree with the installation of command line tools
  4. Continue work where you left over :)
  1. 退出 Xcode 和 iOS 模拟器
  2. 删除/Library/Developer(从根目录中删除),或者如果您想保留备份,则将其重命名
  3. 重新启动Xcode,同意命令行工具的安装
  4. 在你离开的地方继续工作:)

Besides the steps mentioned in the question (fully uninstall Xcode 11, fully uninstall Xcode 10 and reinstall it afterwards), I also tried cloning the project in another location, circulating through all possible locations for derived data, installing other simulator runtimes and trying on those. None of them worked, luckily the console log app shown the path for the process that rejected the app bundle, it was one of the binaries installed by Xcode in /Library/Developer/PrivateFrameworks/CoreSimulator.framework.

除了问题中提到的步骤(完全卸载 Xcode 11,完全卸载 Xcode 10 并在之后重新安装),我还尝试将项目克隆到另一个位置,在所有可能的位置循环获取派生数据,安装其他模拟器运行时并尝试这些. 他们都没有工作,幸运的是控制台日志应用程序显示了拒绝应用程序包的进程的路径,它是/Library/Developer/PrivateFrameworks/CoreSimulator.framework.

Seems that Xcode 11 installed a newer version of the frameworks, and Xcode 10 was not overwriting them. Removing the whole /Library/Developerfolder triggered the command line tools installation, which finally brought back the simulator runtime that properly worked in Xcode 10.

似乎 Xcode 11 安装了较新版本的框架,而 Xcode 10 没有覆盖它们。删除整个/Library/Developer文件夹触发了命令行工具安装,这最终带回了在 Xcode 10 中正常工作的模拟器运行时。

You gotta love the betas :)

你一定喜欢测试版:)

回答by Sgeven.Zheng

I had the same problem. I find the Xcode 11 Beta Release Notes had explain it.

我有同样的问题。我发现 Xcode 11 Beta 发行说明已经解释了它。

Bundles without a CFBundleVersion are invalid and can't be properly installed on 
devices or simulators. CoreSimulator now checks and rejects such bundles earlier in
the process with a clearer error message. (49892531)

And this linkis the format of CFBundleVersion.

而这个链接就是CFBundleVersion的格式。

When I resolved this problem, I found out if having the CFBundleVersion problem when running App for the first time. Then it always has problem no matter whether the format is correct or not. So I restart the Xcode and the Simulator, and change the CFBundleVersion to a correct format, the App running correctly.

当我解决这个问题时,我发现第一次运行App时是否有CFBundleVersion问题。那么无论格式是否正确,它总是有问题。所以我重新启动 Xcode 和模拟器,并将 CFBundleVersion 更改为正确的格式,应用程序正常运行。

回答by catanman

Combining Sgeven.Zheng and Cristik's answers.

结合 Sgeven.Zheng 和 Cristik 的回答。

CAUSE

原因

Installing Xcode11 Beta installs a new version of CoreSimulator.frameworkwith the following update:

安装 Xcode11 Beta 会安装CoreSimulator.framework具有以下更新的新版本:

https://developer.apple.com/documentation/xcode_release_notes/xcode_11_beta_release_notes

"Bundles without a CFBundleVersion are invalid and can't be properly installed on devices or simulators. CoreSimulator now checks and rejects such bundles earlier in the process with a clearer error message. (49892531)"

https://developer.apple.com/documentation/xcode_release_notes/xcode_11_beta_release_notes

“没有 CFBundleVersion 的捆绑包是无效的,无法正确安装在设备或模拟器上。CoreSimulator 现在会在流程的早期检查并拒绝此类捆绑包,并提供更清晰的错误消息。(49892531)”

The following won't fix the issue:

以下不会解决问题:

  • Uninstalling Xcode11 Beta
  • Uninstalling and reinstalling Xcode 10
  • 卸载 Xcode11 Beta
  • 卸载并重新安装 Xcode 10

This is because CoreSimulator.frameworkis installed in /Library/Developer/PrivateFrameworks/CoreSimulator.framework, which is outside the Xcode.appbundle. When re-installed, xcode10 detects that the currently installed version of CoreSimulator.frameworkis newer than what xcode10 would have installed, so it leaves it as-is.

这是因为CoreSimulator.framework安装在 中/Library/Developer/PrivateFrameworks/CoreSimulator.framework,位于Xcode.app捆绑包之外。重新安装时,xcode10 检测到当前安装的版本CoreSimulator.framework比 xcode10安装的版本新,所以它保持原样。

SHORT-TERM FIX

短期修复

  1. Uninstall xcode11
  2. Install Xcode 10 (No need to re-install if it's already installed)
  3. Remove /Library/Developer/PrivateFrameworks/CoreSimulator.framework
  4. Launch Xcode 10 and agree to install command line tools
  1. 卸载 xcode11
  2. 安装 Xcode 10(如果已经安装则无需重新安装)
  3. 消除 /Library/Developer/PrivateFrameworks/CoreSimulator.framework
  4. 启动 Xcode 10 并同意安装命令行工具

LONG-TERM FIX

长期修复

Since this is not a "real" bug but is instead the intended behavior of Xcode11, steps will eventually need to be taken to ensure that apps are always built with a valid CFBundleVersion.

由于这不是“真正的”错误,而是 Xcode11 的预期行为,因此最终需要采取措施确保应用程序始终使用有效的CFBundleVersion.

回答by Omar N Shamali

I went to targets and found "Version" field is empty, just fill a number, for example 1.0

我去了目标,发现“版本”字段是空的,只需填写一个数字,例如 1.0

enter image description here

在此处输入图片说明

回答by Ethan Wen

It's a new feature in Xcode11.

这是 Xcode11 中的一项新功能。

In release note it said:

在发行说明中它说:

Bundles without a CFBundleVersion are invalid and can't be properly installed on devices or simulators. CoreSimulator now checks and rejects such bundles earlier in the process with a clearer error message. (49892531)

没有 CFBundleVersion 的捆绑包无效,无法正确安装在设备或模拟器上。CoreSimulator 现在会在流程的早期检查并拒绝此类捆绑包,并提供更清晰的错误消息。(49892531)

You can:

你可以:

  1. Edit your CFBundleVersion by the style of this LINK
  2. Reset your Xcode and simulator
  3. Run again, you will see it works again
  1. 按此LINK的样式编辑您的 CFBundleVersion
  2. 重置你的 Xcode 和模拟器
  3. 再次运行,你会看到它再次工作

When you run app in simulator success, you can change back your CFBundleVersion again, you will found it still can work XD

当你在模拟器中成功运行应用程序时,你可以再次改回你的 CFBundleVersion,你会发现它仍然可以工作 XD

回答by SamB

In my case, the "Build Version" field on my target was empty, I changed it to 1 and the app was able to install.

就我而言,目标上的“构建版本”字段为空,我将其更改为 1 并且该应用程序能够安装。

回答by StevenTsooo

Adding onto this, I noticed that if your CFBundleVersion does not spec out to:

除此之外,我注意到如果您的 CFBundleVersion 没有指定:

This key is a machine-readable string composed of one to three period-separated integers, such as 10.14.1. The string can only contain numeric characters (0-9) and periods.it will not build on simulator

This key is a machine-readable string composed of one to three period-separated integers, such as 10.14.1. The string can only contain numeric characters (0-9) and periods.它不会建立在模拟器上

link

关联

回答by James Stewart

In my case it was running the simulator/coresimulator version for 11 beta vs the one for 10.1 -> Killing and letting Xcode reopen the simulator solved the problem.

在我的情况下,它正在运行 11 beta 的模拟器/coresimulator 版本与 10.1 的版本 -> Killing 并让 Xcode 重新打开模拟器解决了这个问题。

回答by Ray Barrera

I ran into this same issue as well.

我也遇到了同样的问题。

I didn't get so far as to trying some of the other options provided here, but I was able to get back to building for simulator by simply deleting the /DerivedData directory.

我还没有尝试尝试这里提供的其他一些选项,但是我可以通过简单地删除 /DerivedData 目录来重新构建模拟器。

If you're unsure as to where to find it, simply do this: Xcode -> Preferences -> Locations and select the arrow next to the path for Derived Data

如果您不确定在哪里可以找到它,只需执行以下操作:Xcode -> Preferences -> Locations 并选择派生数据路径旁边的箭头