Xcode 4 - build output directory - ide

I have problems with setting up/locating my output files in Xcode4 (beta 5). They are placed somewhere in ~/Library/Developer/ugly_path/.... I can't even select "show in finder" on my products. It is the same for a simple C project, Foundation tool and even Cocoa bundle. A Debugging works fine.
Could you please point me out where and how to set up / build output directories? (I know it sounds dumb, I've been coding in Xcode3 for months, but I can't figure it out in Xcode4 beta).
Thanks a lot.

From the Xcode menu on top, click preferences, select the locations tab, look at the build location option.
You have 2 options:
Place build products in derived data location (recommended)
Place build products in locations specified by targets
Update:
On xcode 4.6.2 you need to click the advanced button on the right side below the derived data text field. Build Location select legacy.

If you build from command line, you can set output directory in the following way:
xcodebuild -workspace 'WORKSPACE_NAME.xcworkspace' \
-scheme 'SCHEME_NAME' \
-configuration 'Release' \
-sdk iphoneos7.0 CONFIGURATION_BUILD_DIR='OUTPUT_DIRECTORY'

In Xcode 5: Xcode menu > Preferences... item > Locations tab > Locations sub-tab > Advanced... button > Custom option.
Then choose, e.g., Relative to Workspace.

If you have Xcode 4 Build Location setting set to "Place build products in derived data location (recommended), it should be located in ~/Library/Developer/Xcode/DerivedData. This directory will have your project in there as a directory, the project name will be appended with a bunch of generated letters so look carefully.

Keep derived data but use the DSTROOT to specify the destination.
Use DEPLOYMENT_LOCATION to force deployment.
Use the undocumented DWARF_DSYM_FOLDER_PATH to copy the dSYM over too.
This allows you to use derived data location from xcodebuild and not have to do wacky stuff to find the app.
xcodebuild -sdk "iphoneos" -workspace Foo.xcworkspace -scheme Foo -configuration "Debug" DEPLOYMENT_LOCATION=YES DSTROOT=tmp DWARF_DSYM_FOLDER_PATH=tmp build

You can always find the build directory by looking in the build log viewer, and copying the path there into a terminal window.
I use this to analyze my iOS .app bundles before they get installed to make sure no stray files are being included.

For anyone who wants to find the build directory from a script but does not want to change it, run the following to get a list of all the build settings that point to a folder in DerivedData:
xcodebuild -showBuildSettings | grep DerivedData
If you run custom targets and schemes, please put them there as well:
xcodebuild -workspace "Foo.xcworkspace" -scheme "Bar" -sdk iphonesimulator -configuration Debug -showBuildSettings | grep DerivedData
Look at the output to locate the setting output that you want and then:
xcodebuild -showBuildSettings | grep SYMROOT | cut -d "=" -f 2 - | sed 's/^ *//'
The last part cuts the string at the equal sign and then trims the whitespace at the beginning.

If you use the new Xcode4 Workspaces, you can change the Derived Data Location under File -> Workspace settings...

You can configure the output directory using the CONFIGURATION_BUILD_DIR environment variable.
Source: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/0-Introduction/introduction.html#//apple_ref/doc/uid/TP40003931-CH1-SW1

Another thing to check before you start playing with Xcode preferences is:
Select your target and go to Build Settings > Packaging > Wrapper Extension
The value there should be: app
If not double click it and type "app" without the qoutes.

This was so annoying. Open your project, click on Target, Open Build Phases tab. Check your Copy Bundle Resources for any red items.

Related

xcodebuild: error: 'project.pbxproj' is not a project file

I am new to Xcode so I am probably doing something wrong (or missing something in this case). I would appreciate any help.
I've just created a new project on Xcode. New Project -> macOS -> Command Prompt. I've saved it somewhere and as soon as Xcode returns with its main screen on my project's properties, I've closed it. Then cd'd to the folder where my .xcodeproject was (on terminal) and ran xcodebuild install and it returns me that message. Additionally, I tried editing my project Schema from debug to release and closed Xcode again (to make sure everything was saved), same error.
If I build the project from Xcode's UI it works, obviously, it will print Hello World, but I can't run the builder from command line. Does anyone have any tips? Thank you!
This is on Xcode 8.3.3.
I ran into this issue and my fix was due to an overlooked flag in my .gitlab-ci.yml file.
Pretty easy fix :)
So the error says:
xcodebuild: error: '<some file>' is not a project file.
The reason for that was because in my .gitlab-ci.yml file it said -project instead of -workspace
Super easy to overlook. So if you have the: is not a project file error, make sure your flag says -workspace and not -project.
Alternatively if you have the opposite error xcodebuild: error: '<some file>' is not a workspace file then you'll want to change your -workspace flag to -project
My bad... the xcodebuild install command works from one directory up, outside the .xcodeproj folder.

xcodebuild setting parameter equivalent in Xcode GUI build?

I have an Xcode workspace. The workspace has multiple projects. Each project has at least 1 target.
The command xcodebuild allows you to add setting parameters on the command line. These settings are passed to all targets.
For example, I can build everything in the workspace by doing this:
xcodebuild -scheme KitchenSink build BOB=newhart
And the setting BOB=newhart will be passed to every project.
What is the equivalent of this when choosing Product | Build from the Xcode menu bar (pressing Command+B)?
Some points:
I would prefer not to edit every project.
I created an xcconfig file named "Global", but how do I get the Xcode build process to use it for all targets?
The Build section when editing a scheme does not contain a way to attach xcconfig files.
When I select Global.xcconfig in the Navigator pane, and look at the File Inspector in the Utilities pane, I do not see a way to add that file to any targets.
The xcconfig file is only part of the workspace. It is not part of any 1 project.
I'm not certain the use of xcconfig files is how to accomplish what I want; I'm just explaining what I've tried.

Xcode custom shell scripts are slowing down the compiling time

Testing any changes to my Xcode project has become an exercise in patience whenever I build. After all the source files have compiled, I get the following message in the activity window at the top of Xcode:
"Running 3 of 3 Custom Shell Scripts"
I have not added any of my own custom shell scripts but I am using quite a few dependencies via Cocoapods and I am using 2 frameworks for the build environment, Crashlytics and Tapstream. Crashlytics requires you add a run script in the build phases, other than that I don't know where the other ones are coming from and they appear to be the bottleneck in my build time.
Can anyone enlighten me as to what is going on and how i possibly speed it up?
I can't enlighten you but I can tell you how I stopped mine from running. This also happened after installing Cocoapods. In my main project's Target, under Build Phases, I noticed two entries entitled Check Pods Manifest.lock and another called Copy Pods Resources.
Under both there was an unchecked option Run script only when installing. I checked both and at least for now my projects build and run fine without running the scripts.
This is kind of a crappy answer because I can't really give you any more information, and it might not even work for your case, so hopefully someone comes along and enlightens us.
POSSIBLE EXTERNAL BUNDLE ISSUES
So I just had a frustrating experience debugging an issue where a pod installed library's NSLocalized strings file weren't working. Turns out it was because I checked the option mentioned above. Pods-resources.sh, which had the lines to install the bundle, wasn't running in debug mode. It was only running when installing - of course! Something to watch out for.
More info in this question:
NSLocalizedStringFromTable not working in CocoaPod dependency
To fix the slow "Copy pods resources" problem I figured out a solution to only copy the resources if they haven't been copied before.
For this purpose we have to patch the *-resources.sh files that are created by cocoapods such that the copy procedure only happens if a generated file in the target directory doesn't exist (it is created upon first copy). As long as this target directory exists and includes this autogenerated file, the copy resources phase is skipped. This saves me about 30 seconds in my project (of course depends on your project size). To accomplish this do the following:
Create a patch file called 'copy_pod_resources_once.patch' in your project root dir with the following contents:
5a6,13
> NONCE_FILE="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/copyresources-done.nonce"
> if [ -f "$NONCE_FILE" ]; then
> echo "already copied resources"
> exit 0
> else
> touch "$NONCE_FILE"
> fi
>
In the Podfile for your project add the following post install hook:
post_install do |installer_representation|
system('find "./Pods/Target Support Files" -name "*-resources.sh" | xargs -I{} patch -p0 {} -i ./copy_pod_resources_once.patch')
<other post install stuff>
end
For me, it was Crashlytics. There were some outstanding changes, as Crashlytics does auto-updating of its files. I reset/removed them and rebuilt and got past it.
So the general answer may be to check any third party components and make sure they're working properly.
As Ramsel has said in this answer,
https://stackoverflow.com/a/21318086/1752988
I also went to Build Phases and cleared out all the possible links to PODs, after trying most of the other solutions and the three build issues shown regarding Pods were cleared out.
But then one file which was not list under the XCode Project navigator was missing, but they were in the Downloaded Git Zip folder! Obviously, I copied it and put into the XCode project and try running it runs cleanly! :)
I had a similar issue in my project (however not using Cocoapods). It ended up being an issue with an application external to Xcode (Spritebuilder) somehow holding onto a resource within my Xcode project when it crashed. I forced the non-xcode application to close and now the issue is gone
Check your project folder name have any space.Because space creates problem in directory path like "SRCROOT".I removed spaces and project run fine.
I've found that this happens to me frequently. Exact cause unknown, but appears to be switching between git branches that have differences in what pods are being used. In my case simply touching the Pods-xxx-Resources.sh shell script file causes it to speed back up.
Probably not going to work for you, but cleaning the project fixed it for me (Product -> Clean)

Add Version number to XCode Command Line Utility C++ Project

I have created a Command Line Utility C++ tool in XCode using Objective-C. I want the version number to be displayed in the Info of the created executable. So I have added the version number 1.0.0.0 in the Current Project Version field in the Build settings. However, when I build it, the version number does not get added to the created 'Unix Executable File'.
Am I missing something?
Thanks for the help.
Unfortunately, Xcode will not embed the current project version into the executable by itself, as of version 3. I'm not sure if this has changed in Xcode 4.
I ran into this problem a couple of years ago. It turns out that:
Version numbers displayed in the Finder come from applications’ Info.plists. In the case of an application bundle, Info.plist is a file. In the case of an executable, it must be embedded in a __TEXT section. The format of the Info.plist is the same either way.
Xcode does not have one-click support for embedding Info.plists into executables, but it is possible.
Xcode doesn’t preprocess Info.plist files unless they’re going into an application bundle (e.g. to insert the value of CURRENT_PROJECT_VERSION).
I hacked up a solution, but it’s unpolished and probably doesn’t represent best practices.
First, I created a new, stock Info.plist file called Info_template.plist. I set CFBundleVersion to ${CURRENT_PROJECT_VERSION}, and CFBundleShortVersionString to ${CURRENT_MARKETING_VERSION}.
Then, I added a Run Script phase called “Preprocess Info.plist” at the beginning of the build, using /bin/sh as the shell, with this script:
set -u
if ! [[ ${CURRENT_PROJECT_VERSION:-""} && ${CURRENT_MARKETING_VERSION:-""} ]]; then
echo "Version numbers are not set" >&2
exit 1
fi
# Ghetto environment variable expansion, since Xcode does not appear to have built-in expansion for arbitrary files
{ echo "cat <<EOF"
cat ${SRCROOT}/Info_template.plist
echo "EOF"
} | sh > ${DERIVED_FILES_DIR}/Info.plist
I added $(DERIVED_FILE_DIR)/Info.plist to its output files.
Then, I opened the target’s build settings, and added this to Other Linker Flags:
-sectcreate __TEXT __info_plist ${DERIVED_FILE_DIR}/Info.plist
This asks the linker to roll the generated Info.plist file into the executable.
Let me know how this works for you, or if I left anything out!

How do I archive multiple targets with one action in xcode 4

I have a project with multiple targets that are all for different iOS Apps. For instance one traget for the lite version and another one for the pro version.
I want to build and archive all of my Apps at once. Currently I have a scheme for every target which I use to archive each app independently. But now I have to start the archiving, wait until it is done and then start the next one.
Is there a way to archive all apps with one single action in xcode 4 or using the command line?
The Build action in a scheme dictates what targets are built for what actions. Leave the defaults (so they'll all be built for the Archive action). When that scheme is active, it'll build all the requested targets just prior to archiving when you select Product -> Archive.
You could create a new scheme called "All", edit it, then in its Build action, add all targets you want to archive. Then just select that scheme and ask it to archive.
Alternatively, add all targets to your existing scheme and uncheck unwanted actions for which it should build those extra targets, leaving only Archive.
You can use xcodebuild from the commandline
e.x.
xcodebuild -configuration Release -project MyProject -scheme MyProjectScheme clean build
Also you can use xcrun to build an ipa from the commandline as well, see:
https://stackoverflow.com/a/4198166/618419