xcodebuild says does not contain scheme
Asked Answered
C

11

127

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.

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.

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?

Creation answered 16/1, 2013 at 22:18 Comment(1)
Just noticed that when I open the project in xcode is create a .xcscheme file, but in the xcuserdata/username.xcuserdatad folder... but I dont get why the scheme gets 'generated' below the users folder.. and how am I going to handle that in bambooCreation
H
190

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

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.

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:

  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.

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!

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:

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

xcodebuild goes looking for file <'scheme' Parameter Value>.xcscheme existing at <'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:

  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.

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.

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!

Hiatt answered 17/4, 2013 at 1:38 Comment(8)
This actually fixed a random xcodebuild error for me which was returning NO errors but an exit code 65. Turns out the container was set to the project and not the workspace itself, changed it and voila, problem solved. Thanks.Warrenwarrener
MY Test and archive option are disable is that because of this. I have checked my scheme is shared. still not able to build thru bot.I am able to build locally but as I mentioned that I cant archive it. Do you think its related to this problemToulon
Thanks! Setting the scheme container to my workspace fixed the issues I was having with my TeamCity builds.Karenkarena
how to locate the schema from this message. I am getting exactly this message.[ xcodebuild: error: The workspace named "jamesAppV2" does not contain a scheme named "". The "-list" option can be used to find the names of the schemes in the workspace.]Magill
Great, but on my project is not finding the signing certificate now. Running from Terminal worksRoca
I had a problem where xcodebuild was saying that my scheme was not configured for the test action: #48395112. I was building a project, not a workspace. But I went and looked and saw that my scheme was not shared, so I tried that and checked in the resulting file. Problem solved! Thanks!Kenner
Make the scheme shared...gets me every time!Heaton
If you see this message on your CI build and your project IS LISTED as "shared" in your Xcode UI, uncheck it and check it again. You will see that the xcshareddata files will appear in your version control tool as new files. (I was running XCode 11.6 beta)Asphodel
W
56

Debug the issue like this:

xcodebuild -list

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

xcodebuild -workspace MyProject.xcworkspace -list

If you scheme is not listed fix like so:

enter image description here

Withrow answered 1/4, 2014 at 15:18 Comment(1)
Making the schemes shared allows them to show up in xcodebuild -list... thanks!Saxena
D
36

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.

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.

Ruby & xcodeproj gem

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

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

So install it

sudo gem install xcodeproj

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

#!/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 pbxproj file.

Diazonium answered 6/1, 2014 at 2:3 Comment(6)
In case anyone else stumbles across this, it seems that recreate_user_schemes does not handle test targets correctly. I've filed a bug report about it.Rhona
I blogged about it. nsbogan.com/xcode/2014/05/29/share-xcode-schemes. Unfortunately the issue with unit tests is still not fixed.Diazonium
well, I tried this solution. But when I run xcodebuild -project Finance.xcodeproj -scheme "Finance" -configuration Release clean archive CODE_SIGN_IDENTITY="My Identity" I got 'Scheme <IDEScheme:0x7fc9ea5e5fd0:'Finance'> was asked to build and archive, but the run destination <IDERunDestination:0x7fc9eb47c6c0:'iPad 2'> is not a deployment platform and this action shouldn't have been allowed'. But when I open XCode all works fineGaudy
archive action always involves signing and destination must be set to a real device. In your case destination is iPad 2, which I think is simulator, so no archiving is possible. There is one important option missing from your command, it's -sdk iphoneos Try that first and see how it goes. When you run it from Xcode IDE, you probably have the destination set to iOS Device or maybe you have real device plugged in so it's set as a destination. That's why archiving works from IDE. Command line is more "dumb" and can sometimes use "wrong" options by default so you need to be more specific.Diazonium
This should be upvoted more - thank you! Calabash projects with Swift frameworks fail to build with XCode6.1.1 because you have to build them from a scheme. This gem is awesome.Disenthrone
This is also the solution for XCode projects created by Bazel. Thanks for the tip, and the snippet of code!Crosshatch
C
9

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?

Creation answered 16/1, 2013 at 22:28 Comment(0)
O
3

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.

Overstuffed answered 25/2, 2016 at 17:5 Comment(0)
O
1

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.yml file.
After you hav made your scheme availabe by sharing. In Xcode Go to Products>Scheme>Manage Scheme and check share to share.

Changes

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 testDemo with your project name.

Overtask answered 21/6, 2017 at 12:40 Comment(0)
G
1

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 xcode.

Navigate to 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

Goner answered 2/9, 2018 at 9:39 Comment(0)
P
1

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 lanes correctly display all your lanes including all your schemes:

enter image description here

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

enter image description here

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

enter image description here

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

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.

Photogene answered 21/11, 2018 at 10:39 Comment(0)
C
0

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

Craze answered 1/12, 2016 at 3:40 Comment(0)
M
0

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

  1. Select the scheme you want
  2. Press "Edit"
  3. Check the "Shared" box

Scheme Edit Contains Shared Box Now

Muscarine answered 15/5, 2020 at 16:53 Comment(0)
T
0

Make sure your .gitignore not blocking committing .xcworkspace/xcshareddata/ and .xcodeproj/xcshareddata/

And the rest answers state mark target build schemes shared

Thermotensile answered 20/2 at 18:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.