xcodebuild says does not contain scheme

2019-01-12 15:20发布

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?

9条回答
啃猪蹄的小仙女
2楼-- · 2019-01-12 15:57

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?

查看更多
Anthone
3楼-- · 2019-01-12 16:00

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.

查看更多
神经病院院长
4楼-- · 2019-01-12 16:00

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

查看更多
等我变得足够好
5楼-- · 2019-01-12 16:06

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

查看更多
爷、活的狠高调
6楼-- · 2019-01-12 16:09

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.

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

查看更多
一纸荒年 Trace。
7楼-- · 2019-01-12 16:13

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.

查看更多
登录 后发表回答