[英]Can't compile Simulator build with Universal (fat) Framework built with Xcode 10.2+
I can't compile application for Simulator (Device compiles successfully) which use Universal (fat) Framework built with Xcode 10.2+.我无法为使用 Xcode 10.2+ 构建的通用(胖)框架的模拟器(设备编译成功)编译应用程序。 Application use the Framework from Objective-C code.
应用程序使用来自 Objective-C 代码的框架。 When switching from build for Device to build for Simulator Xcode stops to recognize any classes and other entities from the Framework so it doesn't compile (but in Swift files Framework classes recognized properly).
当从为设备构建切换到为模拟器构建时,Xcode 停止识别框架中的任何类和其他实体,因此它不会编译(但在 Swift 文件中正确识别框架类)。
My script to create Universal Framework is similar to https://gist.github.com/sundeepgupta/3ad9c6106e2cd9f51c68cf9f475191fa (in general all such scripts use almost same logic and mostly differs by variable naming).我创建通用框架的脚本类似于https://gist.github.com/sundeepgupta/3ad9c6106e2cd9f51c68cf9f475191fa (通常所有此类脚本使用几乎相同的逻辑,并且主要因变量命名而异)。
The real reason for this issue is in Xcode compiler.此问题的真正原因在于 Xcode 编译器。 Starting Xcode 10.2 Apple changed generator of Framework swift header (MyFramework.framework/Headers/MyFramework-Swift.h).
从 Xcode 10.2 开始,Apple 更改了 Framework swift header (MyFramework.framework/Headers/MyFramework-Swift.h) 的生成器。 Now it adds lines like
现在它添加了像
#elif defined(__x86_64__) && __x86_64__
#elif defined(__i386__) && __i386__
to simulator header and到模拟器标题和
#elif defined(__arm64__) && __arm64__
#elif defined(__ARM_ARCH_7A__) && __ARM_ARCH_7A__
to device header.到设备头。
So headers for simulator and device become different.因此模拟器和设备的标头变得不同。 Because general script for universal framework building copy header from device build directory then such framework works fine with device build but fails with Simulator builds.
因为通用框架构建的通用脚本从设备构建目录复制头文件,所以这样的框架在设备构建中工作正常,但在模拟器构建中失败。
Apple discover this issue in the Xcode 10.2 release notes Known Issues chapter and suggests a solution. Apple 在Xcode 10.2 发行说明的已知问题一章中发现了这个问题并提出了解决方案。
Solution to resolve the issue mentioned by Apple is to create combined header which should include both original headers from device and simulator:解决 Apple 提到的问题的解决方案是创建组合标头,其中应包含来自设备和模拟器的原始标头:
#include <TargetConditionals.h>
#if TARGET_OS_SIMULATOR
<contents of original iOS Simulator/Framework.framework/Framework-Swift.h>
#else
<contents of original iOS/Framework.framework/Framework-Swift.h>
#endif
Regarding mentioned script to make fat Framework you could modify it in next way:关于上面提到的制作胖框架的脚本,您可以通过以下方式对其进行修改:
# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUT_DIR}/${PRODUCT_NAME}.framework" "${RELEASE_DIR}"
# Step 6. Combine PRODUCT_NAME-Swift.h from device and simulator architectures (Xcode 10.2 issue: 48635615)
UNIVERSAL_SWIFT_HEADER=${UNIVERSAL_OUTPUT_DIR}/${PRODUCT_NAME}.framework/Headers/${PRODUCT_NAME}-Swift.h
> ${UNIVERSAL_SWIFT_HEADER}
echo "#include <TargetConditionals.h>" >> ${UNIVERSAL_SWIFT_HEADER}
echo "#if TARGET_OS_SIMULATOR" >> ${UNIVERSAL_SWIFT_HEADER}
cat ${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PRODUCT_NAME}.framework/Headers/${PRODUCT_NAME}-Swift.h >> ${UNIVERSAL_SWIFT_HEADER}
echo "#else" >> ${UNIVERSAL_SWIFT_HEADER}
cat ${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PRODUCT_NAME}.framework/Headers/${PRODUCT_NAME}-Swift.h >> ${UNIVERSAL_SWIFT_HEADER}
echo "#endif" >> ${UNIVERSAL_SWIFT_HEADER}
# Step 7. Convenience step to open the project's directory in Finder
open "${RELEASE_DIR}"
Line > ${UNIVERSAL_SWIFT_HEADER}
needed to clear copied header in step 2 before combine started. Line
> ${UNIVERSAL_SWIFT_HEADER}
需要在合并开始之前清除步骤 2 中复制的标题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.