简体   繁体   English

无法使用使用 Xcode 10.2+ 构建的通用(胖)框架编译模拟器构建

[英]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 (通常所有此类脚本使用几乎相同的逻辑,并且主要因变量命名而异)。

REASON原因

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解决方案

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.

相关问题 无法使用Xcode 10.2中的通用框架编译项目 - Unable to compile project using universal framework in Xcode 10.2 Xamarin.iOS无法编译项目“app是为iOS 10.2构建的,它比这个模拟器更新” - Xamarin.iOS Can't compile project “app was built for iOS 10.2 which is newer than this simulator” 无法在 Xcode 10.2 中的模拟器上运行 iOS 应用程序 - Can't run iOS app on simulator in Xcode 10.2 Xcode 10.2 上的 Swift 通用框架问题 - Swift Universal framework issue on Xcode 10.2 如何为有条件地使用正确框架的设备和模拟器正确构建应用程序。 (不是通用/胖框架) - how to correctly build an app for device and simulator that conditionally uses the correct framework. (not a universal/fat framework) 如何使用 XCode 13 创建 FAT / Universal 框架? - How to create FAT / Universal framework with XCode 13? Xcode-无法编译添加的框架 - Xcode - Can't compile added framework 创建Universal Fat Framework lipo:无法创建临时输出文件 - Creating Universal Fat Framework lipo: can't create temporary output file 通用二进制框架,.../TestTarget 具有相同的架构(arm64),不能在同一个胖 output 文件中 - Universal binary framework, …/TestTarget have the same architectures (arm64) and can't be in the same fat output file Xcode可以构建一个项目但不能在模拟器上运行它 - Xcode can build a project but can't run it on simulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM