为iOS构建应用,但嵌入式框架'xxx.framework'是为iOS + iOS模拟器构建的。

25

升级到Xcode 12.3时,出现错误:

Building for iOS, but the embedded framework 'opus.framework' was built for iOS + iOS Simulator

但在更新之前一切都正常。


我也有同样的问题! - DanielZanchi
1
可能相关:https://dev59.com/qVEG5IYBdhLWcg3wfPEp - Tom Knapen
一个临时的解决方法(对我有效)是使用传统的构建系统 https://dev59.com/o1UK5IYBdhLWcg3w2i3o#54058682 - Tom Knapen
如果您正在使用Cocoapods,那么有一个解决方法。通过Cocoapods分发的框架不会直接嵌入,并且目标完整性检查无法“看到”它们。 因此,您可以将框架打包为本地pod: 1)创建podspec并引用框架 spec.public_header_files = "YourFramework.framework/Headers/*.h" spec.source_files = "YourFramework/Headers/*.h" spec.vendored_frameworks = "YourFramework" 2)从podfile引用框架 - Sergiy Salyuk
这对我有用!谢谢@TomKnapen - skoonppman
2个回答

15

Xcode构建设置

尝试将您的“构建设置”中的“构建选项”下的“验证工作空间”设置为“Yes”,可能会有所帮助。


对于 M1 Mac,使用 Rosetta + 以上选项打开帮助了我。 - Anand
我的已经设置为“否”,但仍然出现此错误。 - IgorGanapolsky

4

编辑:这是一个可以帮助那些使用Carthage的观察结果。

显然,答案中描述的解决此问题的最受欢迎的方法是:

在Build Settings选项卡中将Validate Workspace设置为Yes

此外,答案的观察结果是正确的:

恐怕这实际上是正确的错误,框架不应同时包含iOS和iOS模拟器代码。苹果试图强制我们使用XCFramework来实现这个目的。他们从XCode 11开始推出,并收紧了限制。

除xcframework用法之外,其他所有解决方法似乎在即将发布的Xcode版本中变得越来越临时。


如果你正在使用Carthage并添加了一个带有Embed & Sign的框架,这就是一个问题。

enter image description here

为了使其正常工作,您必须遵循Carthage页面提供的步骤

If you're building for iOS, tvOS, or watchOS

  1. Create a Cartfile that lists the frameworks you’d like to use in your project.

  2. Run carthage update. This will fetch dependencies into a Carthage/Checkouts folder, then build each one or download a pre-compiled framework.

  3. Open your application targets’ General settings tab. For Xcode 11.0 and higher, in the "Frameworks, Libraries, and Embedded Content" section, drag and drop each framework you want to use from the Carthage/Build folder on disk. Then, in the "Embed" section, select "Do Not Embed" from the pulldown menu for each item added. For Xcode 10.x and lower, in the "Linked Frameworks and Libraries" section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

  4. On your application targets’ Build Phases settings tab, click the + icon and choose New Run Script Phase. Create a Run Script in which you specify your shell (ex: /bin/sh), add the following contents to the script area below the shell:

    /usr/local/bin/carthage copy-frameworks
    
  5. Create a file named input.xcfilelist and a file named output.xcfilelist

  6. Add the paths to the frameworks you want to use to your input.xcfilelist. For example:

    $(SRCROOT)/Carthage/Build/iOS/Result.framework
    $(SRCROOT)/Carthage/Build/iOS/ReactiveSwift.framework
    $(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework
    
  7. Add the paths to the copied frameworks to the output.xcfilelist. For example:

    $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Result.framework
    $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ReactiveSwift.framework
    $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ReactiveCocoa.framework
    

    With output files specified alongside the input files, Xcode only needs to run the script when the input files have changed or the output files are missing. This means dirty builds will be faster when you haven't rebuilt frameworks with Carthage.

  8. Add the input.xcfilelist to the "Input File Lists" section of the Carthage run script phase

  9. Add the output.xcfilelist to the "Output File Lists" section of the Carthage run script phase

也许这也是其他情况的临时解决方案。(依赖项未使用Carthage构建)

2
我遇到了OP的问题,但我使用的是CocoaPods而不是Carthage。 - Tom Knapen
是的,我也一样。不使用Carthage。 - hacker_1989
无论是否使用Carthage,此问题都会发生。 - IgorGanapolsky
1
@IgorGanapolsky 我把我的编辑移到了答案的顶部。原始答案解决了使用Carthage时出现的类似问题。 - gcharita

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接