本文介绍了如何在具有不同配置名称的同一个工作空间中编译带有应用程序和库的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发应用程序,并且正在使用开源组件.

I am developing an app and I am using an open source component.

我有一个包含 MyApp.xcodeproj Component.xcodeproj 的工作区.我的应用程序具有三种配置: Debug App Store Inhouse ,但是组件只有两种: Debug 发布

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

Debug 配置中,一切正常,但是我无法在 App Store Inhouse 配置中编译我的应用程序,因为配置名称不匹配.尝试#import <Component/Component.h>

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>

我同时需要 App Store Inhouse 配置,并且我真的很想避免修改组件的配置,以简化组件的将来更新.

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.

我知道我可以使用CocoaPods解决此问题,但我想知道Xcode中是否有简单的解决方案

I know I could use CocoaPods to solve this issue but I would like to know if there is a simple solution in Xcode

推荐答案

您可以通过对应用程序设置进行一些调整来使您的项目进行编译.

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.

  1. 添加新的DEFAULT_CONFIGURATION用户定义的设置并定义您的配置映射.它应该是这样的:

  1. Add a new DEFAULT_CONFIGURATION user-defined setting and define your configuration mapping. This is how it should look like:

将所有配置的FRAMEWORK_SEARCH_PATHS设置为$(BUILD_DIR)/$(DEFAULT_CONFIGURATION)-$(PLATFORM_NAME),添加任何OS X SDK 变体,并将值设置为$(BUILD_DIR)/$(DEFAULT_CONFIGURATION).将HEADER_SEARCH_PATHS设置为$(FRAMEWORK_SEARCH_PATHS)/include,将LIBRARY_SEARCH_PATHS设置为$(FRAMEWORK_SEARCH_PATHS).它应该是这样的:

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). Set HEADER_SEARCH_PATHS to $(FRAMEWORK_SEARCH_PATHS)/include and LIBRARY_SEARCH_PATHS to $(FRAMEWORK_SEARCH_PATHS). This is how it should look like:

此步骤非常繁琐,可以使用 xcproj 工具并在您的项目目录中运行此脚本来使其自动化.根据需要编辑配置映射.

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)'

  • 如果该组件作为静态库分发,则在此处完成.如果组件作为框架提供,则必须通过在文本编辑器中编辑project.pbxproj文件来更新其路径引用.在PBXFileReference部分(在/* Begin PBXFileReference section */下)中找到Component.framework并按如下所示更新其path:

  • 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 */) find Component.framework and update its path like this:

    name = Component.framework; path = "../$(DEFAULT_CONFIGURATION)/Component.framework"; sourceTree = BUILT_PRODUCTS_DIR; };
    

    还要确保将sourceTree设置为BUILT_PRODUCTS_DIR,即相对于内置产品.编辑项目文件后,该外观应如下所示:

    Also make sure that the sourceTree is set to BUILT_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.

    这篇关于如何在具有不同配置名称的同一个工作空间中编译带有应用程序和库的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-21 10:20