简体   繁体   English

Xcode 12 模拟器的构建目标顺序错误?

[英]Xcode 12 build target in wrong order for simulator?

My project always runs correctly on all devices using Xcode 11, but after I installed Xcode 12 beta 4, it is failing to build on the simulator.我的项目始终在使用 Xcode 11 的所有设备上正确运行,但在我安装 Xcode 12 beta 4 后,它无法在模拟器上构建。

I compared the build logs of Xcode 11 and Xcode 12 and it seems in Xcode 12 that my main target is being built before the cocoa pods target, and so the link will fail because the cocoapods library will not be found. I compared the build logs of Xcode 11 and Xcode 12 and it seems in Xcode 12 that my main target is being built before the cocoa pods target, and so the link will fail because the cocoapods library will not be found.

How to fix the order of the build target?如何修复构建目标的顺序?

In Xcode 11, everything is fine.在 Xcode 11 中,一切都很好。 My own target is built after the cocoapods target.我自己的目标是在 cocoapods 目标之后构建的。

在此处输入图像描述

In Xcode 12, the build is out of order My own target is built before the cocoapods target.在 Xcode 12 中,构建出现故障我自己的目标是在 cocoapods 目标之前构建的。

在此处输入图像描述

OK, i got a solution to make the build work (this way to fix problem is not correct, the right way to fix is added in my update) :好的,我得到了一个使构建工作的解决方案(这种解决问题的方法不正确,我的更新中添加了正确的修复方法)

1 you need to add the Pods project to your main project as a external project 1 你需要将Pods项目作为外部项目添加到你的主项目中

2 add all the cocodpods target as dependency explicitly in your main project 's build phase 2 在您的主项目的构建阶段明确添加所有 cocodpods 目标作为依赖项

But i still think may be the new beta version of xcode 12 will fix this.但我仍然认为 xcode 12 的新测试版可能会解决这个问题。 because it seem a bug of xcode 12 ( my project work perfect in xcode 11 and xcode 12 + ios device, failed in xcode 12 + simulator only) because it seem a bug of xcode 12 ( my project work perfect in xcode 11 and xcode 12 + ios device, failed in xcode 12 + simulator only)

###2020-08-17 update### ###2020-08-17 更新###

i found a more exactly reason to reproduce this problem, it seems my project file open in xcode 12 will auto generate a VALID_ARCHS macro in User-Defines, and this macro will make the build failed我找到了重现此问题的更确切原因,似乎我在 xcode 12 中打开的项目文件将在用户定义中自动生成 VALID_ARCHS 宏,并且此宏会使构建失败

在此处输入图像描述

And i found that,with this macro, During in the LINK of building,the link target type will be a unknown type ' arm64-apple-ios11.0-simulator ' which cause the build faild and the problem that all the targets build in wrong order seems will only happen when this macro is being added我发现,使用这个宏,在构建的链接过程中,链接目标类型将是未知类型' arm64-apple-ios11.0-simulator ',这会导致构建失败以及所有目标都内置的问题错误的顺序似乎只会在添加此宏时发生

XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios11.0-simulator 

after i delete this VALID_ARCHS macro, the link target type will be ' x86_64-apple-ios11.0-simulator ', and everything goes well删除此 VALID_ARCHS 宏后,链接目标类型将为“ x86_64-apple-ios11.0-simulator ”,一切顺利

XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-ios11.0-simulator 

####2020-09-11 add Add Apple's Feedback about this macro#### ####2020-09-11 添加添加 Apple 对此宏的反馈####

update Apple's Feedback on VALID_ARCHS 更新 Apple 对 VALID_ARCHS 的反馈
  • After reviewing your feedback, we have some additional information for you:在查看您的反馈后,我们为您提供了一些其他信息:

  • Xcode does not add VALID_ARCHS to your project. Xcode 不会将 VALID_ARCHS 添加到您的项目中。 Indeed, we recommend against using VALID_ARCHS.事实上,我们建议不要使用 VALID_ARCHS。 Maybe some CocoaPod is setting it in your project for some reason?也许某些 CocoaPod 出于某种原因将其设置在您的项目中? CocoaPods are not part of Xcode so, we don't have any control over what they do. CocoaPods 不是 Xcode 的一部分,所以我们无法控制他们的行为。

    One thing to note is that in Xcode 11 VALID_ARCHS showed up under the architectures section.需要注意的一点是,在 Xcode 11 VALID_ARCHS 出现在架构部分下。 Since we are strongly recommending against using it, it no longer shows up there and now appears in the User Defined section if it is defined at all.由于我们强烈建议不要使用它,它不再显示在那里,如果它被定义,现在会出现在用户定义部分中。

  • Xcode 11 used to automatically translate building for arm64 for the simulator into building for x86_64, but now that arm64 is a valid simulator architecture (it's the Apple Silicon architecture), that translation no longer occurs. Xcode 11 用于自动将模拟器的 arm64 构建转换为 x86_64 构建,但现在 arm64 是有效的模拟器架构(它是 Apple Silicon 架构),不再发生这种转换。

  • So, we suspect what you should do is delete VALID_ARCHS from your project altogether, and make sure Architectures (ARCHS) is set to Standard Architectures (ARCHS_STANDARD) and not to something specific (unless you really know exactly why you're not using ARCHS_STANDARD).所以,我们怀疑你应该做的是从你的项目中完全删除 VALID_ARCHS,并确保架构 (ARCHS) 设置为标准架构 (ARCHS_STANDARD) 而不是特定的东西(除非你真的知道你为什么不使用 ARCHS_STANDARD) .

####Feedback end#### ####反馈结束####

####2020-10-10 added#### ####2020-10-10 已添加####

the build may still not working after deleting the VALID_ARCHS macro for some guys, you may check the answer of Apple's feedback added and @Andrei Herford's answer below:删除某些人的 VALID_ARCHS 宏后,构建可能仍然无法正常工作,您可以查看添加的 Apple 反馈的答案和以下@Andrei Herford 的答案:

make sure Architectures (ARCHS) is set to Standard Architectures (ARCHS_STANDARD)确保体系结构 (ARCHS) 设置为标准体系结构 (ARCHS_STANDARD)

and then delete the macro,hope these two steps works for all:)然后删除宏,希望这两个步骤适用于所有人:)

####2020-10-10 added end#### ####2020-10-10 添加结束####

I was able to solve the problem both in simulator and on device by using $(ARCHS_STANDARD) not only for ARCHS in the Architecture settings but also in VALID_ARCHS as well.通过在架构设置中使用 $( VALID_ARCHS ) 以及在ARCHS中使用$(ARCHS_STANDARD) ,我能够在模拟器和设备上解决该问题。 I am not sure what possible side effect changing the archs in this way might have but so far I have not experiencend any new problems.我不确定以这种方式改变拱门可能会产生什么副作用,但到目前为止我还没有遇到任何新问题。

在此处输入图像描述

Details:细节:

The excellent answer by @ximmyxiao got me on the right track. @ximmyxiao 的出色回答让我走上了正轨。 However, the solution proposend by him (remove VALID_ARCHS) did not work for me.但是,他提出的解决方案(删除 VALID_ARCHS)对我不起作用。 This led to a new problem when compiling the Pod targets ( Command PhaseScriptExecution failed with a nonzero exit code and ARCHS[@]: unbound variable in Pods script).这在编译Pod 目标时导致了一个新问题( Command PhaseScriptExecution failed with a nonzero exit code ,并且ARCHS[@]: unbound variable in Pods script)。

Instead replacing arm64 with x86_64 in VALID_ARCHS solved the problem when building for simulator.而是在arm64中用x86_64替换 arm64 解决了为模拟器构建时的问题。 It seems that arm64 was never a correct platform and was translated to x86 by Xcode.似乎arm64从来都不是一个正确的平台,它被 Xcode 翻译成 x86。 As Apple has announced their shift to ARM processors, this translation is not correct anymore and thus one has to use the the correct platform x86_64 instead.由于 Apple 已宣布转向 ARM 处理器,因此这种转换不再正确,因此必须改用正确的平台x86_64

Regarding to Apple VALID_ARCHS should not be used any more.关于 Apple VALID_ARCHS 不应再使用。 However, this fix did not work when building for devices.但是,此修复在为设备构建时不起作用。 Eventually using $(ARCHS_STANDARD) instead (both for simulator and device) did the trick in both cases.最终使用$(ARCHS_STANDARD)代替(对于模拟器和设备)在这两种情况下都可以解决问题。

Good look to others who encounter this kind of problems.遇到此类问题的其他人很好看。 Never gets boring working with Xcode....与 Xcode 一起工作永远不会感到无聊......

** For XCode 12.4 ** ** 对于 XCode 12.4 **

I have Apple MB Pro with M1 and the project with Moya POD and lot of others.我有带有 M1 的 Apple MB Pro 和带有 Moya POD 的项目以及许多其他项目。 App builds perfectly in old intel-based macbook with the same version of XCode (12.4).应用程序在具有相同版本的 XCode (12.4) 的旧英特尔 macbook 中完美构建。 But for M1 it won't compile says: "Moya not found".但对于 M1,它不会编译说:“Moya not found”。 What??什么??

It said: "Could not find module 'Moya' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator".它说:“找不到目标'x86_64-apple-ios-simulator'的模块'Moya';找到:arm64,arm64-apple-ios-simulator”。

No suggestions worked for me.没有任何建议对我有用。 So what helped me is:所以帮助我的是:

  • (not sure whether this is necessary): reinstall all pods by pod install (不确定是否有必要):通过 pod install 重新安装所有 pod
  • clear build data清除构建数据
  • launch via Rosette (check this in XCode app properties cmd+i)通过 Rosette 启动(在 XCode 应用程序属性 cmd+i 中检查)

in App's Project:在应用程序的项目中:

  • "Architectures": add x86_64 “架构”:添加 x86_64
  • "Build Active Architecture Only": YES “仅构建活动架构”:是

in "Pods" project, conflicting pod section (Moya in my case):在“Pods”项目中,冲突的 pod 部分(在我的例子中是 Moya):

  • "Build Active Architecture Only": YES “仅构建活动架构”:是

Then rebuild.然后重建。 Probably next rebuild also required.可能还需要下一次重建。

For Xcode Version 12.1 If you can't find VALID_ARCHS Adding **$(ARCHS_STANDARD) x86_64 i386 all three in Architectures will solve the issue for running on simulators and Devices, archiving.对于 Xcode 版本 12.1 如果找不到 VALID_ARCHS 添加 **$(ARCHS_STANDARD) x86_64 i386架构中的所有三个将解决在模拟器和设备上运行、归档的问题。 also suggestedly add Build Active Architecture Only to ' Yes '.还建议将“仅构建活动架构”添加到“”。 在此处输入图像描述

Here's what worked for me.这对我有用。

  1. Removed VALID_ARCHS from user defined settings从用户定义的设置中删除VALID_ARCHS
  2. Set the ARCHS to $(ARCHS_STANDARD)ARCHS设置为$(ARCHS_STANDARD)
  3. Created a new .xcconfig file for my project.为我的项目创建了一个新的.xcconfig文件。 (If you already have one, then you may skip this) (如果你已经有,那么你可以跳过这个)
  4. Added these to my .xcconfig file将这些添加到我的.xcconfig文件中
EXCLUDED_ARCHS[sdk=iphoneos*] = x86_64 EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64

After that, I'm able to build both for simulator & device.之后,我可以为模拟器和设备构建两者。 The idea here is to exclude arm64 when building on simulators and x86_64 on devices.这里的想法是在模拟器上构建时排除 arm64,在设备上构建 x86_64。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM