我在 Xcode 12.5 中的解决方案是在构建设置或 .xcconfig 文件中添加或添加TARGET_OS_IPHONE
。TARGET_OS_IPHONE=1
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
细节:
更新到 Xcode 12.5 beta 后,现在carthage bootstrap
尝试构建iRate 1.12.2时会失败。我查看了 carthage 构建日志,导致失败的错误是:
error: 'TARGET_OS_IPHONE' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_]
对我来说,问题是 iRate 不再处于开发阶段,我宁愿不分叉 iRate 它只是为了覆盖一些损坏的构建设置。
但是,我从CarthageXCODE_XCCONFIG_FILE=path/to/my.xcconfig
的人们那里学到了一个绝妙的解决方法:您可以在运行之前通过设置环境变量来覆盖使用任何 .xcconfig 文件的任何项目的构建设置xcodebuild
。该 .xcconfig 文件中的任何设置现在都将覆盖您正在构建的任何项目的设置xcodebuild
。
此外,您可以通过调用而不是调用 xcodebuild 的脚本来动态执行此操作,例如:
#!/usr/bin/env bash
# Save this script as 'injectXcodeBuild.sh'
# Run it in place of xcodebuild (all arguments get forwarded through)
# The echo'd commands below will override any settings of the
# projects that get built by xcodebuild through this script.
set -euo pipefail
xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
trap 'rm -f "$xcconfig"' INT TERM HUP EXIT
echo 'GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS=TARGET_OS_IPHONE=1' >> $xcconfig
export XCODE_XCCONFIG_FILE="$xcconfig"
xcodebuild "$@"
或者,如果您需要覆盖某些 Carthage 依赖项的构建设置,则xcodebuild
可以调用此脚本。carthage
它也可能适用于 CocoaPodspod
命令(我不确定)。