32

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.

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. My own target is built after the cocoapods target .

enter image description here

In Xcode 12, the build is out of order My own target is built before the cocoapods target .

enter image description here

ximmyxiao
  • 2,622
  • 3
  • 20
  • 35
  • Maybe https://stackoverflow.com/questions/10285964/build-ordering-in-xcode-scheme-build-targets ? – Larme Aug 13 '20 at 09:14
  • @Larme ,not the same question , the link you post is in the same project , but my project in using workspace , i can't set targets dependency explicitly in different project – ximmyxiao Aug 13 '20 at 09:16
  • @Larme and in fact ,my project is still build ok in xcode 11 , it will build fail in xcode 12 only , so i think it may be some mechanism in xcode cause this problem – ximmyxiao Aug 13 '20 at 09:19
  • https://stackoverflow.com/questions/5752660/what-is-a-target-dependency https://stackoverflow.com/questions/4219054/xcode-adding-a-project-as-a-build-dependency?noredirect=1&lq=1 –  Aug 13 '20 at 12:24
  • @anki,in fact ,i think the denpendency setting is right , because the same project will work perfect in xcode 11 and xcode 12 + ios device , the problem will happen in xcode 12 + simulator only, – ximmyxiao Aug 14 '20 at 00:49
  • 1
    2 answers provided took me in the right direction but didn't solve the problem. This is what worked for me: https://stackoverflow.com/a/63955114/427969 – user427969 Oct 12 '20 at 21:18

5 Answers5

57

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

2 add all the cocodpods target as dependency explicitly in your main project 's build phase

But i still think may be the new beta version of xcode 12 will fix this. 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###

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

enter image description here

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

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

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

####2020-09-11 add Add Apple's Feedback about this macro####

update Apple's Feedback on VALID_ARCHS
  • After reviewing your feedback, we have some additional information for you:

  • Xcode does not add VALID_ARCHS to your project. Indeed, we recommend against using VALID_ARCHS. Maybe some CocoaPod is setting it in your project for some reason? CocoaPods are not part of Xcode so, we don’t have any control over what they do.

    One thing to note is that in Xcode 11 VALID_ARCHS showed up under the architectures section. 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.

  • 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).

####Feedback end####

####2020-10-10 added####

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:

make sure Architectures (ARCHS) is set to Standard Architectures (ARCHS_STANDARD)

and then delete the macro ,hope these two steps works for all:)

####2020-10-10 added end####

ximmyxiao
  • 2,622
  • 3
  • 20
  • 35
  • You should report this to Apple if it's a bug in the simulator only. – matt Aug 14 '20 at 01:29
  • @matt ,in fact i dont know how to feedback to Apple-_- – ximmyxiao Aug 14 '20 at 02:04
  • Can you elaborate on #1 and #2 as to what you did? I am having a similar issue and adding the pods project as a sub project tries to build the pods framework before the components in the pods. – SlashDevSlashGnoll Aug 27 '20 at 14:00
  • @SlashDevSlashGnoll see my way to fix this in the answer's update , i just delete the new user define macro in xcode12 . and everything goes well – ximmyxiao Aug 28 '20 at 01:54
  • sorry, it doesn't works for me, I'm on the final version not on beta. Project was running before the update. – JBarros35 Sep 18 '20 at 12:01
  • I am delete VALID_ARHS and can build in simulator. I spend 2 day to found this problem @ximmyxiao you are super man )) Thanks bro ) – AndrewSas Sep 21 '20 at 12:24
  • 1
    @AndrewSas so glad to help you fix this,bro :) – ximmyxiao Sep 22 '20 at 01:09
  • I my case cocoa pods were adding these configs, I just deleted those and now I am able to run project on simulator. Is there any way we can stop cocoa pods to add these? – Asad Ali Sep 24 '20 at 06:46
  • @AsadAli It seems complicate to decide which one of cocoapods or apple cause this problem , so all we can do is deleting the macro and make the project run:) – ximmyxiao Sep 24 '20 at 08:32
  • 1
    Thanks for the fix, but in xCode 11 VALID_ARCH setting is in another section - "Architectures", so it is present in xCode 11 too. but xCode 12 wont build on Simulator with that setting – RemembranceNN Sep 24 '20 at 20:21
  • 1
    @RemembranceNN,YES, Apple says XCode12 move this macro to User-Defined(because they did not recommended this macro ), seems this movement cause the problem – ximmyxiao Sep 25 '20 at 01:39
  • You can also add x86_64 in valid_archs. It also works in my project. – Tamarous Sep 29 '20 at 02:51
  • @ximmyxiao I am not able to find VALID_ARCHS in Xcode 12.1 ?? Kindly suggest – iMinion Oct 21 '20 at 14:15
  • @iMinion, If your problem is the same problem above , maybe you can check the Architectures or something like arm64 etc configuration in your project file . – ximmyxiao Oct 22 '20 at 03:02
  • @ximmyxiao: I've deleted the VALID_ARCHS still no success :( – Harish Nov 23 '20 at 19:07
  • @Harish ,have you tried the Andrei Herford's answer? – ximmyxiao Nov 24 '20 at 09:25
  • I deleted VALID_ARCHS still issue occures – Nagarjun Dec 02 '20 at 16:23
  • It dissappears in xcode 12 but when i look at the older version of code, I see the valid_arch is set. every time I remove the valid_archs, it appears in xcode 11 again which probably causes an issue. I couldn't find the macro in my project. How can I remove that and avoid this auto regeneration? – jorjj Feb 04 '21 at 22:51
48

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. 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.

enter image description here

Details:

The excellent answer by @ximmyxiao got me on the right track. However, the solution proposend by him (remove VALID_ARCHS) did not work for me. 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).

Instead replacing arm64 with x86_64in VALID_ARCHS solved the problem when building for simulator. It seems that arm64 was never a correct platform and was translated to x86 by Xcode. 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.

Regarding to Apple VALID_ARCHS should not be used any more. 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.

Good look to others who encounter this kind of problems. Never gets boring working with Xcode....

Andrei Herford
  • 17,570
  • 19
  • 91
  • 225
  • 1
    This should be the accepted answer. At least, if you're using CocoaPods! – Jeroen Oct 08 '20 at 07:52
  • Thanks @Andrei Herford,Just as apple says , may be we should make sure Architectures (ARCHS) is set to Standard Architectures (ARCHS_STANDARD) before delete the VALID_ARCHS – ximmyxiao Oct 10 '20 at 00:54
  • 1
    @ximmyxiao In my case ARCHS was already set to to ARCHS_STANDARD but this did not solve the problem. No matter what value I set for VALID_ARCHS. Deleting (= empty) empty VALID_ARCHS with standards ARCHS let to the `ARCHS[@]: unbound variable` error. Only using ARCHS_STANDARD both in ARCHS and in VALID_ARCHS solved the problem. – Andrei Herford Oct 12 '20 at 05:43
  • Apparently this only works whe building for simulator, not for a device. I'll continue trying solutions. – Jeroen Oct 13 '20 at 07:31
  • 1
    @JeroenJK Have you seen my edit I added a few days ago? Changing `arm64` to `x86_64` solved the problem only in simulator. To get the project running on device I had to change `VALID_ARCHS` to `$(ARCHS_STANDARD)` – Andrei Herford Oct 13 '20 at 07:36
  • Ah haven't seen that. When changing that to `$(ARCHS_STANDARD)` (so basically undoing the previous `x86_64` fix), does that fix it for both simulator and device? – Jeroen Oct 13 '20 at 08:19
  • Right now I'm building/uploading (using Fastlane) and so far it's going great; it's past the point were previously I was experiencing problems. Haven't tested this solution for the simulator yet, but I think that will work too! Thanks for your great solution, I spent hours trying different build configurations! – Jeroen Oct 13 '20 at 08:44
  • @AndreiHerford so if I understand you correctly, you set VALID_ARCHS to: simulator -> x86_64 ; device: $(ARCHS_STANDARD. Works for me too, have to remember to change this setting every time but at least a working solution (finally!). – HdN8 Oct 14 '20 at 09:25
  • @HdN8 No, I set `VALID_ARCHS` to `$(ARCHS_STANDARD)` both for simulator AND for device. – Andrei Herford Oct 14 '20 at 10:40
  • 1
    I am not able to find VALID_ARCHS in Xcode 12.1 ?? Kindly suggest – iMinion Oct 21 '20 at 14:15
  • Whoa this worked for me to get it to run on the simulator. I was troubleshooting this forever! – mikengyn Oct 29 '20 at 08:31
  • I'm on Xcode 12.2 and all these suggestions isn't working for me when creating an archive. If I need to edit the project file manually, can someone please guide me. Stuck on this for a couple of days and can't deploy my app. – ArdenDev Nov 23 '20 at 15:48
  • I noticed folks here are putting `$(ARCHS_STANDARD)` in `VALID_ARCHS` which will definitely work. However I don't think the `VALID_ARCHS` user-defined variable is needed anymore. Deleting it should also fix the issue. – KDaker Mar 14 '21 at 03:12
  • @iMinion Try Build Setting > + icon just below that > Add User Defined Setting > Now you can set VALID_ARCHS to $(ARCHS_STANDARD) – samridhgupta May 05 '21 at 22:10
3

** For XCode 12.4 **

I have Apple MB Pro with M1 and the project with Moya POD and lot of others. App builds perfectly in old intel-based macbook with the same version of XCode (12.4). But for M1 it won't compile says: "Moya not found". What??

It said: "Could not find module 'Moya' for target 'x86_64-apple-ios-simulator'; found: 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
  • clear build data
  • launch via Rosette (check this in XCode app properties cmd+i)

in App's Project:

  • "Architectures": add x86_64
  • "Build Active Architecture Only": YES

in "Pods" project, conflicting pod section (Moya in my case):

  • "Build Active Architecture Only": YES

Then rebuild. Probably next rebuild also required.

Sergey
  • 31
  • 3
  • thankss, this finally work to me after try many options – Nicolas Sturm Apr 04 '21 at 07:24
  • holy balls, adding "x86_64" to the projects architectures worked. finally! – Iskeraet Apr 12 '21 at 00:18
  • Also, I've noticed the following pattern: e.g. after the first build to "successful sim" is OK, subsequent builds to another sims are also perfect. But if you starts from "unsuccessful sim", you cannot build. In my case, "successful sim" was sim with ios 13 and "unsuccessful one" was one with ios 14.2. – Sergey Apr 13 '21 at 11:53
2

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 . also suggestedly add Build Active Architecture Only to 'Yes'. enter image description here

iMinion
  • 159
  • 1
  • 14
2

Here's what worked for me.

  1. Removed VALID_ARCHS from user defined settings
  2. Set the ARCHS to $(ARCHS_STANDARD)
  3. Created a new .xcconfig file for my project. (If you already have one, then you may skip this)
  4. Added these to my .xcconfig file
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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
cessmestreet
  • 2,298
  • 3
  • 22
  • 42