I'm trying to build for multiple targets in Xcode, to simplify the process of creating a "lite" and "pro" version of my application. In theory, this is great and I can pass defines to GCC_PREPROCESSOR_DEFINITIONS
for use in my code. However, I'm having problems actually getting it to work due to an error trying to launch the second target in the simulator: Failed to launch simulated application: Unknown error.
Here is the simple process I'm using to create the additional target:
- Add #ifdef MYAPP_PRO to source files to modify behavior based on pro/lite version of app (and verify application is working as expected)
- Select
Project
>New Target...
from menu, and pick "Cocoa Touch Application" (named MyAppPro") - Edit new target settings; add
GCC_PREPROCESSOR_DEFINITIONS
user-defined setting and set the value to "MYAPP_PRO" (no quotes) - Set active target to "MyAppPro"; build and run.
Failed to launch simulated application: Unknown error.
- Copy all settings from Info.plist to MyAppPro-Info.plist and try again
Failed to launch simulated application: Unknown error.
The build completes just fine, but I'm unable to run in simulator.
Editing the project.pbxproj in the .xcodeproj directory, I notice there are some key differences between the two target definitions' build settings. I tried manually editing the file but must have done something wrong because I couldn't get it to load in Xcode afterwards.
Original target's "Debug" build settings:
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = iphoneos2.2.1;
};
Thew new MyAppPro target's "Debug" build settings:
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/UIKit.framework/Headers/UIKit.h";
INFOPLIST_FILE = "MyAppPro-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
OTHER_LDFLAGS = (
"-framework",
Foundation,
"-framework",
UIKit,
);
PREBINDING = NO;
PRODUCT_NAME = MyAppPro;
SDKROOT = iphoneos2.2.1;
};
You didn't say whether you actually ever added source files to the target. A new target (unlike a new project) has no source file templates; you have to add them yourself. So the Simulator might be telling you "you built successfully, but there's nothing to run."
Duplicate the target. I just made the same mistake and realised what I'd done: "New Target" creates is a blank slate (although this is not immediately obvious), even if you try to include things you'll probably miss something.