I am trying to create a new iPhone build target pragmatically with the Ruby gem Xcodeproj. Between my lack of Ruby knowlege and the poor documentation with Xcodeproj, am facing some issues. Here is my code:
require 'rubygems'
require 'xcodeproj'
#get target name from args
scheme_name = ARGV[0]
iosProjectDir = ARGV[1]
# Open the existing Xcode project
project_file = iosProjectDir + '/UserApp.xcodeproj'
project = Xcodeproj::Project.new(project_file)
#Add the target to the project. Are these parameters correct?
app_target = project.new_target(:application, scheme_name, :ios, "8.0")
# Save the project file
project.save(project_file)
When I run this code, a new scheme is made in the XCode project. However, it corrupts all my other build targets and almost all of the projects files disappear. I have to revert the project to get them back. Could this code be corrupting the iOS project?
The only documentation I have found regararding adding a new target is here. I am a bit confused by the optional variable product_group
.
Any ideas as to what I am doing wrong here? I am also open to other methods of adding the target progmatically.
I can't say why yours doesn't work, but I was able to achieve this with:
Which makes me think it could be the use of ARGV to input the scheme name or not saving before creation.
Let me know how you get along. :)