问题
I am developing an app and I am using an open source component.
I have a workspace containing both MyApp.xcodeproj and Component.xcodeproj. My app has three configurations: Debug, App Store and In House but the component has only two: Debug and Release
In the Debug configuration, everything works fine, but I can't compile my app in App Store or In House configuration because the configuration names do not match. I get a file not found error when trying to #import <Component/Component.h>
I need both App Store and In House configurations and I would really like to avoid modifying the component's configurations in order to ease future updates of the component.
I know I could use CocoaPods to solve this issue but I would like to know if there is a simple solution in Xcode
回答1:
You can get your project to compile with some tweaks to your app’s settings.
I suggest you to modify all settings at the project level so that all your targets can inherit these settings.
Add a new
DEFAULT_CONFIGURATION
user-defined setting and define your configuration mapping. This is how it should look like:Set
FRAMEWORK_SEARCH_PATHS
to$(BUILD_DIR)/$(DEFAULT_CONFIGURATION)-$(PLATFORM_NAME)
for all configurations, add Any OS X SDK variants and set the value to$(BUILD_DIR)/$(DEFAULT_CONFIGURATION)
. SetHEADER_SEARCH_PATHS
to$(FRAMEWORK_SEARCH_PATHS)/include
andLIBRARY_SEARCH_PATHS
to$(FRAMEWORK_SEARCH_PATHS)
. This is how it should look like:This step is quite tedious, it can be automated with the xcproj tool and by running this script in your project directory. Edit your configurations mapping as needed.
#!/bin/bash CONFIGURATIONS=( "App Store:Release" "In House:Release" "Debug:Debug" ) for CONFIGURATION in "${CONFIGURATIONS[@]}"; do xcproj --configuration "${CONFIGURATION%%:*}" write-build-setting DEFAULT_CONFIGURATION "${CONFIGURATION#*:}" done xcproj write-build-setting 'FRAMEWORK_SEARCH_PATHS' '$(BUILD_DIR)/$(DEFAULT_CONFIGURATION)-$(PLATFORM_NAME)' xcproj write-build-setting 'FRAMEWORK_SEARCH_PATHS[sdk=macosx*]' '$(BUILD_DIR)/$(DEFAULT_CONFIGURATION)' xcproj write-build-setting 'HEADER_SEARCH_PATHS' '$(FRAMEWORK_SEARCH_PATHS)/include' xcproj write-build-setting 'LIBRARY_SEARCH_PATHS' '$(FRAMEWORK_SEARCH_PATHS)'
If the component is distributed as a static library, you are done here. If the component comes as a framework you have to update its path reference by editing your project.pbxproj file in a text editor. In the PBXFileReference section (under
/* Begin PBXFileReference section */
) findComponent.framework
and update itspath
like this:name = Component.framework; path = "../$(DEFAULT_CONFIGURATION)/Component.framework"; sourceTree = BUILT_PRODUCTS_DIR; };
Also make sure that the
sourceTree
is set toBUILT_PRODUCTS_DIR
, i.e. relative to built products. Once you edited the project file, this should look like:
Your project should now build as expected.
回答2:
I had this same problem, but I had multiple configurations (Debug, TestFlight, Release, Enterprise) in my app, and the bolded configurations would always fail to build cause it couldn't find the frameworks. I really didn't want to mess with the project settings of my sub projects in order to make updating them easy.
The answer I found was to just update the framework search path to account for the fact that the frameworks would be dropped in Release (or whatever the default configuration is set to) of the sub projects.
Specifically I set it to: $(BUILD_DIR)/Release-$(PLATFORM_NAME)
I set it to be recursive too. This works both for Simulator and Device, building in Xcode and command line.
来源:https://stackoverflow.com/questions/30884778/how-to-compile-a-project-with-app-and-library-in-the-same-workspace-with-differe