具有多个项目的工作区中的Xcode构建配置 [英] Xcode Build Configurations in Workspace With Multiple Projects

查看:123
本文介绍了具有多个项目的工作区中的Xcode构建配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Xcode 7.2(7C68),OS X 10.11.2(15C50)

Using Xcode 7.2 (7C68), OS X 10.11.2 (15C50)

tl; dr 在同一Xcode工作区中有多个项目,为什么构建配置的用户定义的构建设置似乎不起作用?我在方案中正确设置了它们,但是在模拟器上运行时,这些值是正确的。在设备上运行时,值是错误的。

tl;dr With multiple projects in same Xcode workspace, why do my user-defined build settings for a build configuration seem to not work? I set them correctly in the scheme, but when run on simulator the values are correct; when run on device, the values are wrong.

您好。我正在尝试利用Xcode构建配置(.xcconfig文件)来根据环境自定义应用程序的行为。这样,我们便可以根据方案的构建配置自动在集成URL和生产URL之间切换。但是,我很难使其正常工作。我认为可能是我的工作空间布局怪异。这是布局/结构:

Hello. I am trying to leverage Xcode build configurations (.xcconfig files) to customize the behavior of our app based upon the environment. This is so that we can switch between integration and production URLs with automatically based upon the scheme's build configuration. However, I am having some difficulty getting it to work properly; I think my workspace layout may be to blame. Here is the layout/structure:


  • Xcode工作区


    • iOS应用程序项目(2个目标:应用程序,测试)

    • 可可触摸框架项目(2个目标:框架,测试)

    现在,对于这些项目的每个,我都有以下.xcconfig文件:

    Now, I have the following .xcconfig files for each of those projects:


    • Debug.xcconfig

    • Testing.xcconfig

    • Release.xcconfig

    • Debug.xcconfig
    • Testing.xcconfig
    • Release.xcconfig

    此外,以下方案(针对每个项目对其配置进行一对一映射):

    Additionally, the following schemes (mapping one-to-one to its respective configuration for each project):


    • Debug

    • 测试

    • 发布

    对于该框架,这些文件包含我们要根据调试,测试或发布自定义的信息(例如URL,API令牌/密钥等)。现在,应用程序和框架都各自拥有这些文件的副本。这是因为在这种情况下,Xcode在处理依赖项或多个项目时会隐式尝试使用相同名称的配置。我想部分原因是我不知道如何明确告诉Xcode使用X配置作为不是所设置配置的依赖项。

    For the framework, these files contain the information we would like to customize based upon debug or testing or release (e.g. URLs, API tokens/keys, etc.). Now, both the app and the framework each have their own copies of those files. This is because Xcode, when dealing with dependencies or multiple projects, implicitly tries to use configurations of the same name in this scenario. I guess part of the issue is I don't know how to explicitly tell Xcode to use X configuration for a dependency that isn't the configuration being set.

    换句话说,如何告诉两者应用程序使用X配置和框架使用Y配置?

    In other words, how do I tell both the app to use X configuration and the framework to use Y configuration?

    现在,当我在模拟器中运行该应用程序时,我知道该方案使用了正确的info.plist值,因为URL和日志设置显示正确。但是,当我在设备上存档或运行时,使用了错误的构建配置。我不知道为什么会这样。

    Right now, when I run the app in the simulator, I know the scheme is using the correct info.plist values because the URLs and log settings appear correct. However, when I archive or run on device, the wrong build configuration is used. I haven't an idea of why this is happening.

    屏幕截图和代码说明了现在的工作原理:

    The screenshots and code illustrate how this works right now:

    图1:

    图2:

    图3(某种方法的部分正文):

    Figure 3 (the partial body of some method):

    if let infoDict = NSBundle(identifier: Constants.uniformTypeIdentifier)?.infoDictionary,
            let apiKey = infoDict[Configuration.SerializationKeys.pusherAPIKey] as? String {
                return apiKey
        }
    

    在框架内部,用户定义构建设置包含需要更改的设置,以进行调试,发布或其他操作(图1)。 Info.plist文件理想地提取给定方案的变量值(图2)。然后在代码中,我从信息plist中检索值(图3)。

    Inside of the framework, user-defined build settings contain settings that need to change for debug vs release vs whatever (Fig. 1). The Info.plist file extracts variable values for a given scheme ideally (Fig. 2). Then in code I retrieve the values from the info plist (Fig. 3).

    任何设备都拒绝使用生产值(包括当我这样做时)在方案的运行操作和存档操作上手动进行切换-存档使用会返回设备上的错误构建设置。

    Any device just refuses to use the production values when told to do so, including when I switch it manually on my scheme's Run action as well as the Archive action - the archive uses returns the wrong build settings on device.

    抱歉,很长,谢谢您阅读。

    Sorry this is long and thank you for reading.

    推荐答案

    最终,我决定采用类似的方法,如下所示:

    Ultimately, I decided with a similar approach as seen here:

    如何在同一工作区中具有不同配置名称的应用程序和库编译项目?

    它在父项目中添加了构建设置,以指导其如何在子项目中查找所需内容。另外,我需要获取嵌入的.framework文件,并相对于构建路径并使用配置设置对其进行设置。我确实忽略了变体,只对所有值使用了 $(BUILD_DIR)/ $(DEFAULT_CONFIGURATION)-$(PLATFORM_NAME)而不是放弃平台名称来最终获得成功。

    It adds build settings inside the parent project to direct it on how to find what it needs in the child project. Additionally, I needed to take the embedded .framework file and set it relative to the build path and using the configuration setting. I did leave out the variants and just used $(BUILD_DIR)/$(DEFAULT_CONFIGURATION)-$(PLATFORM_NAME) for all values instead of leaving off the platform name to finally achieve success.

    在我了解和发现更多信息后,将更新此帖子。

    Will update this post as I learn and discover more.

    Update:2016-2-29:

    Update: 2016-2-29:

    我删除了.xcconfig文件;

    I removed the .xcconfig files; they were not necessary.

    但是,在尝试在嵌入式框架中实际使用第三种方案时,我遇到了困难。我尝试切换 DEFAULT_CONFIGURATION ,但设置不成立。忽略一些细节,即使指定了正确的构建目录,Xcode在使用父级的构建配置设置时也会忽略此细节,并将所有产品都构建在同一目录中,我也认为这是 Build Implicit Dependencies以及嵌入式框架构建阶段。但是,如果要删除这些文件然后将其安装到设备上,则该应用程序会因为找不到框架文件而在启动时崩溃。

    But, I've run into difficulty when trying to actually use the third scheme in the embedded framework. I tried toggling DEFAULT_CONFIGURATION but the settings did not hold. Omitting some details, basically even if the right build directory is specified, Xcode ignores this when using a parent's build config setting and builds all products in the same directory, which I also believe is a result of "Build Implicit Dependencies" as well as the "Embed Frameworks" build phase. But if you were to remove these and then install to device, the app crashes at launch because it cannot find the framework file.

    要继续...

    这篇关于具有多个项目的工作区中的Xcode构建配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆