简体   繁体   中英

Multiple Targets in Xcode: “Failed to launch simulated application: Unknown error.”

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:

  1. Add #ifdef MYAPP_PRO to source files to modify behavior based on pro/lite version of app (and verify application is working as expected)
  2. Select Project > New Target... from menu, and pick "Cocoa Touch Application" (named MyAppPro")
  3. Edit new target settings; add GCC_PREPROCESSOR_DEFINITIONS user-defined setting and set the value to "MYAPP_PRO" (no quotes)
  4. Set active target to "MyAppPro"; build and run.
  5. Failed to launch simulated application: Unknown error.
  6. Copy all settings from Info.plist to MyAppPro-Info.plist and try again
  7. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM