xcodebuild PRODUCT_NAME - ios

I'm able to change my Product name with CLI xcodebuild but when I open my project I still have the old name. I would like to affect my product name's project permanently with CLI.
Is it possible ? Or perhaps I'm doing something wrong :
/usr/bin/xcodebuild -configuration Debug PRODUCT_NAME="NewName"

Passing PRODUCT_NAME to xcodebuild invocation will not change the product name in project but only in this particular build. You need to set it via Xcode in GUI mode if it needs to be done permanently. Look here

Try the following:
Hint 1
how-to-change-the-product-name-with-command-line-builds
/usr/bin/xcodebuild -configuration Debug BUILD PRODUCT_NAME="NewName".
You might have to add BUILD keyword there.
Make sure you have CLEAN your configuration as well

Related

iOS Carthage "project has no shared schemes" even with manual xcodebuild

What does this error mean exactly?
If a project doesn't have shared schemes is it possible to create them somehow with xcodebuild -list -project Whatever.xcodeproj?
There seems to be little support for react-native using carthage. I am able to add react-native in my Cartfile and after running carthage update as see react-native in Checkouts. But I also see the error "project has no shared schemes".
So, I manually ran xcodebuild -list -project Carthage/Checkouts/react-native/React/React.xcodeproj - with the idea to do that for all Libraries in react-native, however I'm still unable to do something like #import "React/RCTRootView.h" or import React.
What am I missing?
Try going into Xcode > Products > Scheme > Manage Scheme and making sure your project's scheme is shared.

Why when generating .app file, xcode needs to be open?

I'm writing a script to build and generate an .app file from an specific target and scheme (to work with simulator). I was using something like:
DEVELOPER_DIR=$xcode_app_path/Contents/Developer xcodebuild -sdk iphonesimulator -scheme "${SCHEME}" -target "${TARGET}" ONLY_ACTIVE_ARCH=NO CONFIGURATION_BUILD_DIR="${build_folder}" clean build
The problem is, that I need to open XCode for the code above to work, otherwise will show me a message telling me that:
xcodebuild: error: The project 'Project-name' does not contain a scheme named "${SCHEME}"
I still yet, don't understand what is XCode doing in background. But if I open the IDE and run the script, works. If I open and later close it, and run the script works. It's not working if the project hasn't been opened first with XCode ¬¬
Any suggestion would be appreaciated
If someone is facing the same experience, this is what I found out. And works.
Well, apparently when you create a new scheme through command line, by default is not "shared". So when you start to link to the folder
xcshareddata --> xcschemes
(trying to build with command line, for example) there's nothing to link with. Xcode do this automaticaly under the hood when you open your project...
The guys from CocoaPods were facing the same issue, so they created a Ruby gem that shares the scheme and place the file in his xcscheme folder:
This is the repo: https://github.com/CocoaPods/Xcodeproj
Also, thanks to this post and this post I found out how to use xcodeproj gem, and change the shared option with a script that I put downhere:
require 'xcodeproj'
xcproj = Xcodeproj::Project.open("MyProject.xcodeproj")
xcproj.recreate_user_schemes
xcproj.save

Target Properties changes by xcodebuild command

How can i manipulate my iOS Target Properties by xcodebuild command tool ?
In example, i have one project with one target and with Facebook SDK Key in Target Properties in Info tab
FacebookAppID: 01234567891234
And with console command xcodebuild i'm compiling two Apps with Developer and Production provisions with two console commands:
For Developer:
xcodebuild -project Projectname.xcodeproj clean install OBJROOT=ObjRoot ... CODE_SIGN_IDENTITY={iPhoneDeveloper} PROVISIONING_PROFILE="Dev.mobileprovision"
For Distribution:
xcodebuild -project Projectname.xcodeproj clean install OBJROOT=ObjRoot ... CODE_SIGN_IDENTITY={iPhoneProduction} PROVISIONING_PROFILE="Prod.mobileprovision"
And i need use in Developer one FacebookAppID, and in Production a other FacebookAppID, and how i can change my command lines for realize this?
Thanks
Arguments to xcodebuild are best used for values that change every time they're invoked, like a destination directory that includes a build number.
For data as foundational as a Facebook app ID, I'd recommend using your build configurations, e.g. "Debug" and "Release". Create a user-defined build setting (in Xcode 5.0.2, Editor -> Add Build Setting -> Add User-Defined Setting) named something like "FACEBOOK_ID", and in your Info.plist, set your desired key's value to ${FACEBOOK_ID}. In your target's build settings, define FACEBOOK_ID differently for your Debug and Release configurations. Your code then now has to pull the current value out of Info.plist at runtime.
If you really want to override build settings as arguments to xcodebuild, you can do so, just by adding "FACEBOOK_ID=12341234" to the end of the command, but this only works if you've done the work I just described to make FACEBOOK_ID into a configuration-specific build setting. I can't think of any sound reasons to keep this kind of app data outside of a build configuration.
If build configurations are new to you, I'd suggest starting with WWDC 2012 session 408, "Working with Schemes and Projects in Xcode".

Passing compiler flags through xcodebuild

I'm currently using xcodebuild to automate testing for iOS.
Right now, I'm stuck on trying to pass compiler flags through Xcode directly to the compiler. These flags are: -fprofile-arcs -ftest-coverage.
I don't have the liberty of modifying the xcodeproj, that's why I want to inject these flags via the xcodebuild command.
It would be something like:
xcodebuild -project path/to/my.xcodeproj -scheme MyApp -fprofile-arcs -ftest-coverage
Is that feasible? How?
Apparently most compiler flags can be expressed as constants, and these can be passed to the compiler via xcodebuild easily.
To get them, simply select the option in the xcode build settings view, and hit command-C (copy). In my case, they were GCC_GENERATE_TEST_COVERAGE_FILES and GCC_INSTRUMENT_PROGRAM_FLOW_ARCS.
My command roughly looks like this:
xcodebuild GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES ...
To set compiler flags with xcodebuild, you need to put them in the OTHERCFLAGS option.
For example:
xcodebuild -project path/to/my.xcodeproj -scheme MyApp \
OTHERCFLAGS="-fprofile-arcs -ftest-coverage"
Yes, all of the compiler setting actually boils down to string key-value pairs. I answered a very similar question about setting preprocessor macros from the command line that is just as applicable to these settings you would like to set:
Setting a #define from the command line in xcode 4.6
I would also like to call attention to the use of ${inherited} -- using this values allows you to use the Xcode project-specified values AND append your own. Documentation for each of the build settings including those that you located via copy-paste can be found here:
http://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html
Glad you were able to get it to work -- now you can really make xcodebuild do even more for you without requiring changes of the target Xcode project!

Implicit dependencies do not work with xcodebuild

I have a little problem with one of my projects. In my workspace I have my main project and a lot of projects for static libraries. When I build from Xcode, everything works fine, but with xcodebuild, one of my project is not built, it seems that implicit dependencies do not work.k. Maybe I did something wrong with my configuration. So there it is.
My scheme configuration:
My QAPreferences.a information:
My target settings:
From Xcode, if I build with buildAppTarget in debug for iphoneos, it works.
From xcodebuild, with command below, QAPreferences project is not built.
xcodebuild -workspace myProject.xcworkspace -scheme buildApp -configuration Debug -sdk iphoneos
It worked before, but I recently added QAPreferences, and it does work since this moment. Maybe the problem comes from QAPreferences project...
Regards,
Quentin
So I finally found why the QAPreferences was not build through xcodebuild but I still do not understand the reason. In fact QAPreferences 'Build Archive Architecture Only' was set to YES, I just set it to NO and now it works!
I had a similar issue but forgot to specify the -workspace argument to xcodebuild, which led to it seeming like the implicit dependencies weren't working correctly. I realize this wasn't the issue with the original question, but for people having issues with implicit dependencies, this could be helpful.

Resources