xcode xcodebuild 说不包含方案

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14368938/
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-09-09 04:42:47  来源:igfitidea点击:

xcodebuild says does not contain scheme

xcodexcodebuildbamboo

提问by Zac Tolley

I have a curios issue.

我有一个古玩问题。

I have a project that I've worked on and always built from the XCode IDE, and it worked fine. Now I'm setting up Bamboo to build the project and as such am building it from the command line.

我有一个项目,我一直在使用 XCode IDE 构建它,并且它运行良好。现在我正在设置 Bamboo 来构建项目,因此我正在从命令行构建它。

The issue is, if I check my code out of GIT and then use xcodebuild to build it it says that the scheme cannot be found, but if I open the project, it builds and if I then try to build it again from the command line with the same command, it works.

问题是,如果我从 GIT 中检查我的代码,然后使用 xcodebuild 来构建它,它会说找不到该方案,但是如果我打开该项目,它会构建,然后如果我尝试从命令行再次构建它使用相同的命令,它可以工作。

What magic is XCode doing when I open the project or am I doing something dumb, maybe excluding a file in my .gitignore that I shouldn't?

当我打开项目或者我在做一些愚蠢的事情时,XCode 有什么神奇之处,也许排除了我不应该在我的 .gitignore 中的文件?

回答by Bryan Musial

You are definitely on the right track with respect to the .xcscheme file -- I had this problem appear while setting up my own projects!

关于 .xcscheme 文件,您绝对是在正确的轨道上——我在设置自己的项目时出现了这个问题!

For posterity, or at least anyone getting here from a search, here are two versions of things -- the "I'm busy, so just the facts please" version and a more involved discussion and rationale. Both of these versions assume you are trying to build from a Workspace file; if you aren't then my apologies as this mostly applicable to workspace-based projects.

对于后代,或者至少任何通过搜索来到这里的人,这里有两个版本的事情——“我很忙,所以请提供事实”版本和一个更复杂的讨论和基本原理。这两个版本都假设您正在尝试从 Workspace 文件构建;如果您不是,那么我很抱歉,因为这主要适用于基于工作区的项目。

Condensed 'Fix-it' Version

精简的“修复”版本

The root cause is that the default behavior of Schemes is to keep schemes 'private' until they are specifically marked as shared. In the case of a command-line initiated build, the Xcode UI never runs and the xcoderun tool doesn't have its own cache of Schemes to work with. The goal is to generate, share, and commit the scheme you want Bamboo to run:

根本原因是 Schemes 的默认行为是将方案保持为“私有”,直到它们被明确标记为共享。在命令行启动构建的情况下,Xcode UI 永远不会运行,并且 xcoderun 工具没有自己的 Schemes 缓存来使用。目标是生成、共享和提交您希望 Bamboo 运行的方案:

  1. On a clean working copy of the code, open your Project's workspace.
  2. Choose Scheme > Manage Schemes... from the Product Menu.
  3. The list of Schemes defined for the project appears.
  4. Locate the Scheme Bamboo is trying to run
  5. Ensure the 'Shared' box is checked for that scheme and that the 'Container' setting is set to the Workspace and not the project file itself.
  6. Click 'OK' to dismiss the Manage Schemes sheet.
  7. A new .xcscheme file has been created in your project at WorkspaceName.xcworkspace/xcshareddata/xcschemes.
  8. Commit this file to your repository and run a Bamboo build.
  1. 在代码的干净工作副本上,打开您的项目工作区。
  2. 从产品菜单中选择方案 > 管理方案...。
  3. 出现为项目定义的方案列表。
  4. 找到 Bamboo 正在尝试运行的 Scheme
  5. 确保为该方案选中“共享”框,并将“容器”设置设置为工作区而不是项目文件本身。
  6. 单击“确定”以关闭“管理方案”表。
  7. 已在您的项目中的 WorkspaceName.xcworkspace/xcshareddata/xcschemes 中创建了一个新的 .xcscheme 文件。
  8. 将此文件提交到您的存储库并运行 Bamboo 构建。

Deeper Discussion and Rationale

更深入的讨论和理由

Xcode 4 introduced Workspaces and Schemes as a way to help try and tame some of the chaos that is inherent to dealing with the mechanics of wiring related Xcode projects, build targets, and build configurations together. The workspace itself has its own set of configuration data that describes each of the smaller 'boxes' of data it contains and acts as a skeleton for attaching .xcodeproj files and a set of shared configuration data that gets mirrored to each developer machine or CI system. This is both the power and pitfall of Workspaces -- there are 1) lots of ways in which one can get things configured 100% correctly, but put into the wrong container or 2) put into the correct container, but configured improperly thus rendering data inaccessible by other parts of the system!

Xcode 4 引入了工作区和方案,以帮助尝试和驯服一些固有的混乱,这些混乱是处理相关 Xcode 项目、构建目标和构建配置的机制所固有的。工作区本身有自己的一组配置数据,这些数据描述了它包含的每个较小的数据“盒子”,并充当附加 .xcodeproj 文件的框架和一组镜像到每个开发人员机器或 CI 系统的共享配置数据. 这既是 Workspaces 的强大之处,也是它的陷阱——有 1) 有很多方法可以使事物 100% 正确配置,但放入错误的容器中或 2) 放入正确的容器中,但配置不当从而呈现数据系统的其他部分无法访问!

The default behavior of Xcode 4 schemes is to automatically generate new schemes as projects are added to the Workspace file. Those of you that have added several .xcodeproj files may have noticed that your scheme list quickly becomes unruly especially as project files are added, then removed, and then readded to the same workspace. All schemes, autogenerated or manually created, default to being 'private' schemes visible only to the current user even when .xcuserdata files are committed with the project's data and configuration. This is the root cause of that cryptic build error Bamboo reports from xcodebuild -- Because Bamboo operates the build through the command line and not the Xcode UI, it doesn't have an opportunity for Schemes to get automatically generated and relies only on those that are defined in the workspace itself. Assuming you've configured Bamboo to build from a workspace using a command like this:

Xcode 4 方案的默认行为是在将项目添加到工作区文件时自动生成新方案。那些添加了多个 .xcodeproj 文件的人可能已经注意到,您的方案列表很快就会变得不规则,尤其是在添加、删除项目文件,然后将其读入同一个工作区时。所有方案,自动生成或手动创建,默认为仅对当前用户可见的“私有”方案,即使 .xcuserdata 文件与项目的数据和配置一起提交。这是 Bamboo 从 xcodebuild 报告的那个神秘构建错误的根本原因——因为 Bamboo 通过命令行而不是 Xcode UI 操作构建,它没有机会让 Schemes 自动生成并且只依赖于那些在工作区本身中定义。

xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyApplication -configuration Debug

xcodebuild goes looking for file <'scheme' Parameter Value>.xcscheme existing at <'workspace' Parameter Value>/xcshareddata/xcschemes.

xcodebuild 去寻找文件 <'scheme' Parameter Value>.xcscheme 存在于 <'workspace' Parameter Value>/xcshareddata/xcschemes。

Obviously there are bunches of ways in which one could configure both Bamboo and a workspace, so keep in mind that your unique configuration may not map 100% to what is presented here. The key takeaways:

显然,有多种方式可以同时配置 Bamboo 和工作区,因此请记住,您的独特配置可能无法 100% 映射到此处显示的内容。关键要点:

  1. Certain automated tasks the Xcode UI magically takes care of are not available via the Xcodebuild CLI.
  2. You can attach scheme and build configuration data to many places in the 'container hierarchy' -- Make sure your data winds up in the right container (Workspace, Project, and/or Build Target)
  3. Consider where in the container hierarchy the xcodebuild tool may be looking for configuration data; a great indicator of where it will start looking is based on the use of '-workspace' or '-project' arguments.
  1. Xcode UI 神奇地处理的某些自动化任务无法通过 Xcodebuild CLI 使用。
  2. 您可以将方案和构建配置数据附加到“容器层次结构”中的许多位置——确保您的数据在正确的容器(工作区、项目和/或构建目标)中结束
  3. 考虑 xcodebuild 工具可能在容器层次结构中的哪个位置寻找配置数据;它将从哪里开始寻找的一个很好的指标是基于“-workspace”或“-project”参数的使用。

The 'Shared' box is already checked...now what?

“共享”框已经被选中......现在怎么办?

I encountered this same issue on my own Bamboo instance; it turned out that the scheme that was committed in my repository was outdated and the latest version of the command line tools wasn't handling it gracefully. Since this existed previously, I took a look through the settings to make sure there wasn't anything glaringly custom about the scheme, deleted and recreated the scheme ensuring that I marked it as 'Shared', and recommitting the new .xcscheme file to the repository.

我在自己的 Bamboo 实例上遇到了同样的问题;事实证明,在我的存储库中提交的方案已经过时,并且最新版本的命令行工具无法正常处理它。由于这之前存在,我查看了设置以确保没有任何关于该方案的明显自定义,删除并重新创建该方案以确保我将其标记为“共享”,并将新的 .xcscheme 文件重新提交到存储库。

If everything looks good and rebuilding it doesn't solve the issue, double check that container setting -- it is really easy to get that scheme attached to the wrong container in the hierarchy!

如果一切看起来都不错并且重建它不能解决问题,请仔细检查该容器设置——很容易将该方案附加到层次结构中的错误容器!

回答by Robert

Debug the issue like this:

像这样调试问题:

xcodebuild -list

or if you are using a workspace (e.g. with pods)

或者如果您正在使用工作区(例如使用 Pod)

xcodebuild -workspace MyProject.xcworkspace -list

If you scheme is not listed fix like so:

如果您的计划未列出,请像这样修复:

enter image description here

在此处输入图片说明

回答by i4niac

Most of the answers would suggest you to make your scheme shared using Xcode, then commit changes to repo. That works, of course, but only if you have access to source code and have rights to commit changes, and couple of other assumptions.

大多数答案都会建议您使用 Xcode 共享您的方案,然后将更改提交到 repo。这当然有效,但前提是您有权访问源代码并有权提交更改以及其他一些假设。

But there's a number of "what ifs" to consider

但是有许多“假设”需要考虑

  • What if you just can't modify the Xcode project for some reason?
  • What if you create a new scheme automatically on CI server?
    This actually happens quite often. If you use test automation framework, like Calabash, you'll normally end up duplicating an existing target, which automatically duplicates a scheme as well, and the new scheme is not shared, even if the original scheme was.
  • 如果您出于某种原因无法修改 Xcode 项目怎么办?
  • 如果你在 CI 服务器上自动创建一个新方案怎么办?
    这实际上经常发生。如果您使用测试自动化框架,如 Calabash,您通常最终会复制现有目标,这也会自动复制方案,并且新方案不会共享,即使原始方案是共享的。

Ruby & xcodeproj gem

Ruby & xcodeproj gem

I would recommend using xcodeprojRuby gem. This is a really cool open source tool that can help you to automate tons of Xcode-related tasks.

我建议使用xcodeprojRuby gem。这是一个非常酷的开源工具,可以帮助您自动化大量与 Xcode 相关的任务。

Btw, this is the gem used by CocoaPodsto mess around with your Xcode projects and workspaces.

顺便说一句,这是CocoaPods用来处理 Xcode 项目和工作区的 gem 。

So install it

所以安装它

sudo gem install xcodeproj

Then write a simple Ruby script to re-share all the schemes, the gem has recreate_user_schemesmethod for that purpose

然后编写一个简单的 Ruby 脚本来重新共享所有方案,gem为此具有recreate_user_schemes方法

#!/usr/bin/env ruby
require 'xcodeproj'
xcproj = Xcodeproj::Project.open("MyProject.xcodeproj")
xcproj.recreate_user_schemes
xcproj.save

It doesn't just copy scheme files form user's folder to xcshareddata/xcschemes, it also creates those files first by parsing the pbxprojfile.

它不仅将用户文件夹中的方案文件复制到xcshareddata/xcschemes,它还首先通过解析pbxproj文件来创建这些文件。

回答by Zac Tolley

Ok I know its 2 minutes later but I found another stack overflow that says the scheme has to be set to shared... Where does Xcode 4 store Scheme Data?

好的,我知道它在 2 分钟后,但我发现另一个堆栈溢出说必须将方案设置为共享... Xcode 4 在哪里存储方案数据?

回答by Eric

One common reason for the scheme to be missing is forgetting to push the commits to the origin. If you get a missing scheme message, you should first verify the scheme is shared, then verify you have committed the changes AND pushed them to the origin server.

该方案丢失的一个常见原因是忘记将提交推送到源。如果您收到一个丢失的方案消息,您应该首先验证该方案是共享的,然后验证您已提交更改并将它们推送到源服务器。

回答by Siddhartha S. Ikshavaku

I had this error while implementing CI.The Question above is identical to my problems except I am using Gitlab's own CI tool.You can check if there is any such file in Bamboo.
I solved it by making some changes to gitlab-ci.ymlfile.
After you hav made your schemeavailabe by sharing. In Xcode Go to Products>Scheme>Manage Schemeand check share to share.

Changes

我在实现 CI 时遇到了这个错误。除了我使用 Gitlab 自己的 CI 工具之外,上面的问题与我的问题相同。您可以检查 Bamboo 中是否有任何此类文件。
我通过对gitlab-ci.yml文件进行一些更改来解决它。
在您scheme通过共享获得可用空间后。在 Xcode 中转到Products>Scheme>Manage Scheme并选中共享以共享。

变化

Set absolute path everywhere.
eg.xcodebuild clean archive -archivePath /path/to/your/project/build/testDemo -scheme testDemo | xcpretty
here you need to change /path/to/your/project/with your path and testDemowith your project name.

到处设置绝对路径。
例如。xcodebuild clean archive -archivePath /path/to/your/project/build/testDemo -scheme testDemo | xcpretty
在这里,您需要更改/path/to/your/project/路径和testDemo项目名称。

回答by Carlos Robles

I faced this issue and even if some of the answers here actually provide the solution, I didn't find it very clear. So I will just add one more. In a nutshell how to share a schema from excode.

我遇到了这个问题,即使这里的一些答案实际上提供了解决方案,我也没有发现它很清楚。所以我再补充一个。简而言之,如何从 excode 共享架构。

Navigate to Product> Scheme> Manage Schemes

导航至Product> Scheme>Manage Schemes

enter image description here

在此处输入图片说明

You will then be shown a list of schemes, with each denoted as being shared or not. Just check the ones that you want to share (it may be different ones for dev and prod builds)

然后,您将看到一个方案列表,每个方案都表示是否共享。只需检查您要共享的那些(开发和生产构建可能是不同的)

enter image description here

在此处输入图片说明

Images taken from this article https://developer.nevercode.io/docs/sharing-ios-project-schemes

图片来自本文https://developer.nevercode.io/docs/sharing-ios-project-schemes

回答by Seto Elkahfi

I want to add solution for my case related to this thread. This one is for you who clone existing project, with all the schemes you need are already being shared:

我想为与此线程相关的案例添加解决方案。这是为克隆现有项目的您准备的,您需要的所有方案都已共享:

enter image description here

在此处输入图片说明

, with fastlane lanescorrectly display all your lanes including all your schemes:

,fastlane lanes正确显示您的所有车道,包括您的所有方案:

enter image description here

在此处输入图片说明

, but fastlane gymonly show main schemes (not dev and test schemes):

,但fastlane gym只显示主要方案(不是开发和测试方案):

enter image description here

在此处输入图片说明

The solution is to uncheck the shared option for schemesthat not listed by fastlane gymand then check it again. It will generates .xcscheme for the schemes:

解决方案是取消选中未列出的方案的共享选项fastlane gym然后再次选中。它将为方案生成 .xcscheme:

enter image description here

在此处输入图片说明

Now, if you check with fastlane gym, all the schemes will be listed:

现在,如果您检查fastlane gym,将列出所有方案:

enter image description here

在此处输入图片说明

Then you should commit those .xcshemes file to the repository, so other developer who clone the project will get the files.

然后您应该将这些 .xcshemes 文件提交到存储库,以便其他克隆项目的开发人员将获得这些文件。

回答by green0range

For anyone with Xcode 11.4 trying to find "Shared" button on scheme, it's now moved into the individual scheme.

对于使用 Xcode 11.4 试图在方案上找到“共享”按钮的任何人,它现在已移入个人方案。

  1. Select the scheme you want
  2. Press "Edit"
  3. Check the "Shared" box
  1. 选择你想要的方案
  2. 按“编辑”
  3. 选中“共享”框

Scheme Edit Contains Shared Box Now

方案编辑现在包含共享框

回答by htzfun

Got the same problem but during building with xcode as subproject of main one. Built subproject in xcode standalone - after that this error disappeared.

遇到了同样的问题,但是在使用 xcode 作为主要项目的子项目进行构建时。在独立的 xcode 中构建子项目 - 之后这个错误消失了。