705

I am trying to get a large (and working on Xcode 11!) project building in Xcode 12 (beta 5) to prepare for iOS 14. The codebase was previously in Objective-C, but now it contains both Objective-C and Swift, and uses pods that are Objective-C and/or Swift as well.

I have pulled the new beta of CocoaPods with Xcode 12 support (currently 1.10.0.beta 2).

Pod install is successful. When I do a build, I get the following error on a pod framework:

building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

and possibly also the error:

Unable to load standard library for target 'arm64-apple-ios11.0'

When I go run lipo -info on the framework, it has: armv7s armv7 i386 x86_64 arm64.

Previously, the project had Valid Architectures set to: armv7, armv7s and arm64.

In Xcode 12, that setting goes away, as per Apple's documentation. Architectures is set to $(ARCHS_STANDARD). I have nothing set in excluded architectures.

What may be going on here? I have not been able to reproduce this with a simpler project yet.

pkamb
  • 30,595
  • 22
  • 143
  • 179
btxios
  • 7,225
  • 3
  • 8
  • 7
  • 3
    This is worked for me: https://stackoverflow.com/questions/24924809/the-file-myapp-app-couldnt-be-opened-because-you-dont-have-permission-to-vi/64016147#64016147 – Narendar Singh Saini Sep 23 '20 at 10:12
  • 1
    Check out the article: https://milanpanchal24.medium.com/xcode-12-building-for-ios-simulator-but-linking-in-object-file-built-for-ios-file-for-8c0cc28ec832?sk=adfc406c1f4fae81155cd4a49ec7edb4 – MilanPanchal Dec 14 '20 at 08:01
  • 14
    I have an Apple Silicon M1, and am still running into this arm64 error. Why would that be the case? – Aspen Dec 23 '20 at 20:24
  • 2
    Same here, Apple M1, just started to happen. None of the solutions I can find seem to work.. any one any idea?? building for iOS Simulator, but linking in object file built for iOS, file '/.............../Pods/GoogleMaps/Maps/Frameworks/GoogleMapsCore.framework/GoogleMapsCore' for architecture arm64 – martin010 Feb 28 '21 at 22:36
  • I (using XCode 12.4 on my dev environment and App Center pipeline that uses Xcode2.2) have tried all the suggestions on this thread. None of them have fixed my issue. The app now runs on simulator as well as on device but fails consistently to **archive** using generic setting **Any iOS Device (arm64 armv7)**. The error shows up after it hits command `~\clang -target armv7-apple-ios10.0` giving me the error **ld: framework not found Pods_XXX** – Yoku Mar 03 '21 at 19:02
  • @martin010 have you solved the issue, I have the same problem as you (...Pods/GoogleMaps/Maps/Frameworks/GoogleMapsCore.framework/GoogleMapsCore) – Alif Al-Gibran Oct 29 '21 at 08:48
  • Conversely, if you want to build with arm64 bc now you have Apple M1, in Applications folder, r-click on Xcode icon, select `Get Info`, and check the `open using rosetta` option. Relaunch Xcode or CLI – Mike S. Jan 18 '22 at 20:21
  • 3
    TLDR; XCode 13 + Apple M1: (1) Open Xcode using Rosetta (Applications -> Right-Click Xcode -> Get Info -> Check Open with Rosetta). (2) Add `arm64` to excluded architectures (Build Settings) (3) Clean Build Folder (4) Run app – Ryan Cocuzzo Jan 21 '22 at 05:55
  • That's ok for cocoapods, but What about the SDKs imported with SPM? Still have the issue .. Any idea? – arcangel06 Jan 30 '22 at 01:27
  • Nothing worked for me except: https://stackoverflow.com/a/70939338/10678427 – Srd Mathur Feb 01 '22 at 10:57
  • https://stackoverflow.com/a/70939338/10678427 This worked for me. It may work for you as well. – Srd Mathur Feb 01 '22 at 10:59
  • 1
    can we have a selected answer to guide people that come to this post? – Andre Cytryn Mar 31 '22 at 17:57

50 Answers50

1054

Basically, you have to exclude arm64 for the simulator architecture, both from your project and the Pod project,

  • To do that, navigate to Build Settings of your project and add Any iOS Simulator SDK with value arm64 inside Excluded Architecture.

    Enter image description here

OR

  • If you are using custom XCConfig files, you can simply add this line for excluding simulator architecture.

    EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64
    

    Then

    You have to do the same for the Pod project until all the Cocoa pod vendors are done adding following in their Podspec.

    s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
    s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
    

    You can manually add the Excluded Architecture in your Pod project's Build Settings, but it will be overwritten when you use pod install.

    In place of this, you can add this snippet in your Podfile. It will write the necessary Build Settings every time you run pod install.

    post_install do |installer|
      installer.pods_project.build_configurations.each do |config|
        config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
      end
    end
    
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Amit Samant
  • 11,043
  • 1
  • 8
  • 14
  • 1
    @DominatorVbN So all dependancies for a Podspec has to exclude right? – cvb Sep 21 '20 at 22:58
  • 11
    The extra detail about CocoaPods here is nice. Note that without `[sdk=iphonesimulator*]` after `EXCLUDED_ARCHS`, XCode will fail to find your pods when building for an actual device since none of the pods will be built for arm64. – mwu Sep 22 '20 at 17:34
  • @ChrisVanBuskirk Yes every Dependencies and there Sub Dependencies need to exclude, as of now many cocoapod vender are already exculid via there Podspec, but until all have done migrating we can attach this little snippet in out pod file to exclude it while installing the pod. – Amit Samant Sep 23 '20 at 05:46
  • It's working in the device & getting error in Simulator. – thevikasnayak Sep 29 '20 at 04:32
  • 16
    Worked for me! Note that there is already a `post_install do |installer|` section in most Podfiles due to flipper. Paste the inner section ```installer.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" end``` behind the `flipper_post_install(installer)` line. – Ramon Vermeulen Sep 29 '20 at 09:59
  • 28
    I am getting `building for iOS Simulator, but linking in object file built for macOS, for architecture x86_64`. How to fix it? – Sazzad Hissain Khan Oct 01 '20 at 13:56
  • 3
    This solution is excellent and I would add that if you are building your own pod, take note particularly of the 2 lines the author suggests after "...until all the cocoa pod vendors are done adding in their Podspec" as the absence of these in my own framework's Podspec was causing linting failures when I attempted to push it to my private repo. Thanks! – Danny Oct 03 '20 at 06:19
  • @user3335999 could you share what the error you are facing. – Amit Samant Oct 06 '20 at 07:10
  • Note: You have to repeat step one for every scheme you have – Hibbem Oct 14 '20 at 08:15
  • 1
    The solution has a flaw that causes trouble since pod spec authors have found and applied this solution. The problematic part is the use of `user_target_xcconfig`. Since multiple pod specs define differing values for `EXCLUDED_ARCHS` they are in conflict and CocoaPods emits warnings like this `[!] Can't merge user_target_xcconfig for pod targets: [... list of pods ...]. Singular build setting EXCLUDED_ARCHS[sdk=<...>] has different values.` The podspec syntax reference says this attribute is "not recommended" https://guides.cocoapods.org/syntax/podspec.html#user_target_xcconfig – leberwurstsaft Oct 16 '20 at 07:09
  • I suggest checking out https://stackoverflow.com/a/64150387/2399348 – Jeroen Oct 16 '20 at 08:42
  • 1
    Thank you for your answer! Could you explain why this is required? – Wojciech Kulik Oct 19 '20 at 10:54
  • 3
    @WojciechKulik https://stackoverflow.com/a/64139830/11857852 this answer explains nicely what has been changed in Xcode, our simulator now run on x86 but the framework tries to build for arm64 too. – Amit Samant Oct 21 '20 at 11:02
  • 1
    if my podspec includes dependencies (for example ss.dependency 'Mantle', '2.1.4') how to exclude arm64 for this dependency too? seems that if I just add s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } it doesn't affect dependencies – phnmnn Oct 21 '20 at 12:07
  • 3
    Why doesn't it detect the active architecture isn't arm64? – Jonathan. Oct 28 '20 at 15:34
  • This worked for me. I had multiple targets. So Excluded Architectures added to the "Project", not to the "Targets" – sameera madushan Nov 03 '20 at 19:58
  • if use apple silicon dtk to run project , have same problem ,how to fix ? Device: DTK mac mini, Xcode version: 12.2 rc, run to ios simulator which arch is arm 64. Throw error : building for iOS Simulator, but linking in object file built for iOS, for architecture arm64 – jiawei wang Nov 12 '20 at 02:00
  • @jiaweiwang what about the `ONLY_ACTIVE_ARCH` solution that I have mentioned here: https://stackoverflow.com/a/64139830/2650641? – Ayan Sengupta Nov 16 '20 at 04:22
  • 14
    This ends up working sometimes, but is actually wrong and broken. EXCLUDED_ARCHS for arm64 on the simulator means that people with Apple Silicon macs won't be able to use your framework. The fix that actually worked for me was to clear out VALID_ARCHS as per https://stackoverflow.com/a/63714000/234 – Orion Edwards Dec 06 '20 at 09:40
  • 1
    So, if I understand well, this is only a valid solution for people having this issue with an Intel Mac? Not for people having a M1 mac? – Xiiryo Dec 13 '20 at 23:14
  • 1
    In the new 12.3 Xcode, if you exclude the architecture, it no longer finds the framework. I submitted this as a bug and opened a ticket with Apple. Will update when I have info. – RandallShanePhD Dec 15 '20 at 16:16
  • man, you saved my day. Anyone who comes here from react native and have this https://github.com/wix/Detox/issues/2554 issue, this solution works perfectly. – Kasra Dec 26 '20 at 14:44
  • Besides the project I had to do this inside the project folder -> CordovaLib.xcodeproj file to make it work. – Joesy_Mosk Jan 24 '21 at 22:33
  • 2
    Unfortunately, recommending that pods add those lines to their podspec is actually going to cause a lot of problems. Having a single pod with that `user_target_xcconfig` line in its podspec will cause the app to not build properly for simulators on an Apple Silicon Mac. And it's really hard to track down, because the error will manifest when it tries to import another pod that has been (correctly) built for arm64, making it look like a problem with a different pod. – Chris Vasselli Jan 26 '21 at 18:14
  • 2
    This is not an answer - it is a temporary workaround. You need to contact the vendors of your dependencies and ask them to vend proper XCFrameworks that contain the arm64 Simulator slice. Excluding the arm64 slice can significantly impact Simulator performance on M1 devices. – Tony Arnold Feb 16 '21 at 22:24
  • May I know the reason behind of such solution? – Cheok Yan Cheng Apr 17 '21 at 17:57
  • This is not working at my end. I have added frameworks in the project. It build successfully but when I use it in example project. It says image not found for frameworks. – Jignesh Patel May 24 '21 at 11:30
  • then for device? – famfamfam May 26 '21 at 12:10
  • I'm able to build & run on Simulator on Apple Sillicon, but unit tests for internal frameworks do not run with this – zalogatomek Jun 24 '21 at 20:50
  • thanks for the podfile script as manually adding in each pod target is so frustrating. – Ammar Mujeeb Jul 25 '21 at 13:08
  • I am not using pod in my objective-c project. Facing the error. But the above solution not worked in 12.5.1. – sejn Aug 14 '21 at 10:49
  • Xcode - 13 ??? just try adding excluded-architecture - both debug and release to : arm64, & build excluded architecture to: yes – abhish Jan 12 '22 at 13:37
  • 1
    BEST ANSWER!!! THANKS BRO! – SwiftiSwift Jan 26 '22 at 13:41
  • I wonder since we need arm64 for real devices, why do we exclude arm64 in simulators on M1? Are arm64 in devices and simulators different? – allenlinli Feb 15 '22 at 02:49
  • This helped me fix the issues when moving my SwiftUI project from an intel machine to the M1 Pro. Had to ensure that "All" & "Combined" are selected in options for the Architectures configs to show – cherucole Apr 16 '22 at 12:07
248

TL;DR;

Set "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" to Yes for your libraries/apps, even for release mode.


While trying to identify the root cause of the issue I realized some fun facts about Xcode 12.

  1. Xcode 12 is actually the stepping stone for Apple silicon which unfortunately is not yet available (when the answer was written). But with that platform we are going to get an arm64-based macOS where simulators will also run on the arm64 architecture unlike the present Intel-based x86_64 architecture.

  2. Xcode usually depends on the "Run Destination" to build its libraries/applications. So when a simulator is chosen as the "Run Destination", it builds the app for available simulator architectures and when a device is chosen as the "Run Destination" it builds for the architecture that the device supports (arm*).

  3. xcodebuild, in the Xcode 12+ build system considers arm64 as a valid architecture for simulator to support Apple silicon. So when a simulator is chosen as the run destination, it can potentially try to compile/link your libs/apps against arm64 based simulators, as well. So it sends clang(++) some -target flag like arm64-apple-ios13.0-simulator in <architecture>-<os>-<sdk>-<destination> format and clang tries to build/link against an arm64-based simulator that eventually fails on an Intel based Mac.

  4. But xcodebuild tries this only for Release builds. Why? Because, "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" build settings is usually set to "No" for the "Release" configuration only. And that means xcodebuild will try to build all architectural variants of your libs/apps for the selected run destination for release builds. And for the Simulator run destination, it will includes both x86_64 and arm64 now on, since arm64 in Xcode 12+ is also a supported architecture for simulators to support Apple silicon.

Simply putting, Xcode will fail to build your application anytime it tries the command line, xcodebuild, (which defaults to release build, see the general tab of your project setting) or otherwise and tries to build all architectural variants supported by the run destination. So a simple workaround to this issue is to set "Build Active Architecture Only (ONLY_ACTIVE_ARCH)" to Yes in your libraries/apps, even for release mode.

Enter image description here

Enter image description here

If the libraries are included as Pods and you have access to .podspec you can simply set:

spec.pod_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES' }

spec.user_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES' } # not recommended

I personally don't like the second line since pods shouldn't pollute the target project and it could be overridden in the target settings, itself. So it should be the responsibility of the consumer project to override the setting by some means. However, this could be necessary for successful linting of podspecs.

However, if you don't have access to the .podspec, you can always update the settings during installation of the pods:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings["ONLY_ACTIVE_ARCH"] = "YES"
    end
  end
end

One thing I was concerned about that what will be the impact of this when we actually archive the libraries and applications. During archiving applications usually take the "Release" configuration and since this will be creating a release build considering only the active architecture of the current run destination, with this approach, we may lose the slices for armv7, armv7s, etc. from the target build. However, I noticed the documentation says (highlighted in the attached picture) that this setting will be ignored when we choose "Generic iOS Device/Any Device" as the run destination, since it doesn't define any specific architecture. So I guess we should be good if we archive our app choosing that as a run destination.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Ayan Sengupta
  • 4,836
  • 2
  • 24
  • 39
  • 5
    This is really a surprising change from Apple and costed me half a day to figure out that I feel Apple should compensate :). This is not a documented update (at least as I know of) and certainly going to affect everyone upgrading to Xcode 12. I only hope everybody finds their own way to get over with it once they know the basics. – Ayan Sengupta Oct 01 '20 at 20:12
  • 2
    If multiple pod specs use `user_target_xcconfig` and the values don't match exactly, CocoaPods will emit warnings like this `[!] Can't merge user_target_xcconfig for pod targets: [... list of pods ...]. Singular build setting EXCLUDED_ARCHS[sdk=<...>] has different values.` The podspec syntax reference says this attribute is "not recommended" https://guides.cocoapods.org/syntax/podspec.html#user_target_xcconfig. So please don't use `user_target_xcconfig` for this to save many developers the trouble. – leberwurstsaft Oct 16 '20 at 07:12
  • 2
    Right! And I think I already have mentioned that in my answer. – Ayan Sengupta Oct 16 '20 at 13:39
  • 1
    I think this is the best solution because it doesn't break building with Xcode 11. I applied this setting for the whole project, then I didn't have to set it for Pods or targets separately. And it works then both on Xcode 11.7 and Xcode 12. Excluding arch `arm64` is mapped in Xcode 11.7 to `x86_64` therefore it excludes main architecture for simulator. – Wojciech Kulik Oct 21 '20 at 11:09
  • 1
    Thanks! I had all my problems solved using https://stackoverflow.com/a/64150387/2399348, or so I thought. Today when trying to build a release version for simulator I came into trouble again. This solution seems to work in combination with the linked answer – Jeroen Oct 21 '20 at 12:58
  • Thanks! I haven't actually yet figured out if this will work for me, but regardless I have upvoted you for providing a detailed and reasoned answer! – Airsource Ltd Oct 26 '20 at 20:17
  • @AirsourceLtd let me know if you can find some loopholes that I need to introspect. Frankly I myself am desperately looking for a situation where it's gonna fail and I will have to find some other way around. – Ayan Sengupta Oct 27 '20 at 15:32
  • 2
    I managed to get it all working in the end with 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' but only in pod_target_xcconfig, and only on the problem pod (which included a prebuilt library) and the single pod which depended on the problem pod. Everything else was left clean. I decided I preferred that to the active arch solution. – Airsource Ltd Oct 28 '20 at 16:31
  • Would not building only the active architecture cause issues with release builds during App Store/TestFlight submission? – Balázs Vincze Nov 03 '20 at 14:23
  • 1
    @BalázsVincze No it won't. 1. Building for only active architecture when a specific run destination is chosen (simulator/iPhone/iPad) will build for only active architecture that the device supports. 2. For "Any iOS device" run destination (which is used for archiving during submission) -- "This setting will be ignored when building with a run destination which does not define a specific architecture, such as a 'Generic Device' run destination.", as per documentation. Please see the last paragraph of my answer. I personally have submitted my apps several times with this setting on. – Ayan Sengupta Nov 03 '20 at 19:06
  • 1
    Adding the snippet to the Podfile, Clean and Build worked for me. Thank you – ferdil Nov 14 '20 at 16:19
  • 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:49
  • @ArdenDev you can post a separate question describing your issue. It's really impossible to figure out anything from your comment alone. – Ayan Sengupta Nov 24 '20 at 12:37
  • 2
    On Apple Silicon, doing this lead to another error. This may be due to some specific pods. I opened a specific question for theses cases. https://stackoverflow.com/questions/65364886/react-native-on-apple-silicon-m1-the-linked-library-libpods-projectname-a-is – Xiiryo Dec 19 '20 at 12:51
  • 1
    @Xiiryo thanks.See my comment to your question. – Ayan Sengupta Dec 19 '20 at 19:38
  • Super helpful!! Thanks a lot for the clarification! – Julie Zhou Jan 12 '21 at 21:10
  • This should be the accepted answer, as it explains the reason for the problem. I had been able to test both on simulators and devices, but couldn't get the profiler to run, this workaround solved it. Thanks! – Pacificana Feb 11 '21 at 09:23
  • It's the best answer with many useful information & explanation. Thank you so much! – nahung89 May 05 '21 at 15:20
  • I am getting Showing All Errors Only Build input file cannot be found: '/Users/name/Library/Developer/Xcode/DerivedData/app-ecboaqtowbxrpjbrefynpxlxmyxr/Build/Products/Debug-iphonesimulator/app hello.app/App Hello' – sejn Aug 14 '21 at 10:53
  • @sejn you have mentioned file missing in your working tree. Please verify if it is there searching from Project Navigator. But this is completely out of the scope of this answer. You can create a separate question if you feel. – Ayan Sengupta Aug 14 '21 at 15:48
  • I have created a separate question too. But the file is mentioned in the Derived data folder. I not found that file. https://stackoverflow.com/questions/68726099/build-input-file-cannot-be-found-in-xcode-12-5-1 – sejn Aug 16 '21 at 04:47
  • @AyanSengupta Can I able to create the similar files. Or how can I found the reference in the app? – sejn Aug 16 '21 at 05:24
  • @AyanSengupta If I remove the product name it works fine. But I can't able to install the file and got /Users/name/Library/Developer/Xcode/DerivedData/Project-hbaothufasjichbdcaldiltth/Build/Products/Debug-iphonesimulator/.app is not a valid path to an executable file.Please rebuild the project to ensure that all required executables are created. Check your project settings to ensure that a valid executable will be built. – sejn Aug 16 '21 at 07:50
  • 1
    @sejn added a comment against your question. – Ayan Sengupta Aug 17 '21 at 13:02
  • This seem to be the simplest & most sensible solution! It works flawless on the Intel Mac, I have sent my changes for a M1 colleague to test. – Rafael Nobre Aug 25 '21 at 16:45
  • 2
    This is good workaround when building for simulator on Intel based Mac on Xcode > 12, to hint Xcode that we are building for simulator having x86_64 architecture. Unfortunately it does not work for M1 & simulator (where you can as workaround run Xcode on Rosetta and include whats proposed by Ayan Sengupta). Proper answer is really done by Tony Arnold - it's all about having proper ARM slice (and XCFramework conversion) for simulator in your Pod, and should be done by vendor of Pod. – Erkki Nokso-Koivisto Jan 12 '22 at 08:16
  • @ErkkiNokso-Koivisto On my Intel Mac I have the same problem when trying to debug in simulator. When I set `ONLY_ACTIVE_ARCH` to `YES` I get `Command PhaseScriptExecution failed with a nonzero exit code`. Switching to the legacy build system reveals what the issue is: `No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=, EXCLUDED_ARCHS=( i386, arm64 )).` Kinda stuck right now. I'm dealing with legacy Pods, I really can't upgrade them all right now. What else can I do? Can anybody help me please? – Martin Braun Feb 04 '22 at 12:30
  • @MartinBraun why do you need legacy build system at the first place? If it is failing for both of your build systems there should be something in your build log irrespective of the build system use. I believe it will be helpful if you can post a new question with details of what you are doing and what your build log shows. – Ayan Sengupta Feb 04 '22 at 13:43
125

I found a solution! SwiftUI Previews not working with Firebase

If you set excluded architectures for the simulator to arm64 it will compile.

Excluding architectures for the simulator

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
SlashDevSlashGnoll
  • 1,853
  • 1
  • 11
  • 15
  • Fair enough, the issue I was having was with a manually linked library however it did not cause a problem with our pods we're using either. – SlashDevSlashGnoll Aug 31 '20 at 12:55
  • 13
    I was testing on **Release** mode so I had to add it to Release too – MujtabaFR Sep 20 '20 at 18:40
  • I think we are back in the business after this post. thank you it helped. – JBarros35 Sep 21 '20 at 08:19
  • @btxios I'm running into the "ARCHS[@]: unbound variable" issue when creating an archive . Were you able to resolve this issue ? – ArdenDev Nov 22 '20 at 17:23
  • I'm I wrong if I say this won't work if you're developing on M1 MacBook? – surfrider Nov 23 '21 at 13:39
  • This got me past the initial build failure, but past that there were 30+ new bright red errors all over the place in multiple packages. – slothstronaut Jan 17 '22 at 16:42
  • This worked for me, but only when I build for arm64; simulators don't work. Small rant: xCode is ridiculous, 12.5 gigs, tons of pods. Building for Android is a walk in the park compared to this experience. – tyler.frankenstein Apr 13 '22 at 03:16
  • 1
    This won't work on M1 mac – atineoSE May 11 '22 at 13:23
  • I only needed this for M1 Mac and it works (without Rosetta; with Rosetta I didn't have this problem at all) The answer, for me, is in the project that I'm trying to compile 1. Architectures are standard 2. Build active is NO 3. Excluded is Debug -> Any iOS Sim SDK -> arm64 but all other slots are blank Hopefully this helps somebody else, too. – Dan Rosenstark May 22 '22 at 21:04
78

The proposed answers are outdated/incorrect.

You should initially try to update both CocoaPods and the dependencies for your library/app, and then, if that doesn't work, contact the vendors of any dependencies you are using to see if they have an update in progress to add support for arm64 Simulator slices on M1 Macs.

There are a lot of answers on here marked as correct suggesting that you should exclude arm64 from the list of supported architectures. This is at best a very temporary workaround, and at worst it will spread this issue to other consumers of your libraries. If you exclude the arm64 Simulator slice, there will be performance impacts on apps that you're developing in the Simulator (which in turn can lead to reduced battery time for your shiny new M1 kit while you're developing your amazing ideas).

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Tony Arnold
  • 2,350
  • 21
  • 34
  • 4
    That's true, as mangling with excluding or including architectures works solely on i386-based machines. – elfenlaid Feb 21 '21 at 11:26
  • Tell that to GOOGLE... They still don't support SPM. It'll be years. – Beau Nouvelle Sep 28 '21 at 04:21
  • 3
    this answer should be the correct accepted answer. @BeauNouvelle Google recently opened sourced lots of their SDKs (like GoogleSignIn) which now supports xcframework with arm64 simulator slices ;) – Buju Oct 04 '21 at 14:21
  • 1
    I agree, this is the correct answer, however, sometimes you have to deal with legacy stuff. On Intel I had to go with the answer from @AyanSengupta to being able to test my debug build. – Martin Braun Feb 04 '22 at 12:01
  • This is correct, but still doesn't offer a workable alternative for unmaintained projects unfortunately – Pranav Kasetti Apr 22 '22 at 12:46
70

The Valid Architectures build setting has been removed in Xcode 12. If you had values in this build setting, they're causing a problem and need to be removed.

I was able to "clear out" the VALID_ARCHS build setting by adding it back in as a user-defined build setting (with no values), running the project (which failed), and then deleting the VALID_ARCHS build setting. After that, I was able to run on the simulator.

My Architectures build setting is Standard Architectures.

You can add a user-defined setting from the plus button in Build Settings:

User-defined setting

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
trishcode
  • 2,875
  • 1
  • 17
  • 21
  • 14
    This should be the accepted answer. Make sure the app project is selected not the Target. Otherwise, you won't be able to delete the VALID_ARCHS from Build Settings. :) – Bionicle Sep 05 '20 at 07:55
  • 2
    @trishcode Even after doing this i'm getting same error(xcode12 beta4), any work arounds – Sivakrishna Perla Sep 08 '20 at 10:16
  • 3
    @SivakrishnaPerla If you can open the project in Xcode 11, then you can see exactly which targets Valid Architectures is used on. You could even clear the setting in Xcode 11, and then try the project again in Xcode 12. If you still need a workaround and you're getting the error on an embedded framework, then SlashDevSlashGnoll's answer should work. If you need a workaround and you're getting the error on a Cocoapod, then exclude the arm64 architecture in the Podfile post install. – trishcode Sep 08 '20 at 12:57
  • 2
    @trishcode Thanks, Setting arm64 in excluded architecture and removing VALID_ARCHS worked. – Sivakrishna Perla Sep 08 '20 at 13:35
  • 1
    If I remove VALID_ARCHS and add arm64 to Excluded architecture, I get this error - Check dependencies No architectures to compile for (ARCHS=arm64 x86_64, VALID_ARCHS=, EXCLUDED_ARCHS=( arm64 )). – nOOb iOS Sep 14 '20 at 16:08
  • @nOObiOS I'm assuming after you removed Valid Archs that you tried to run without excluding arm64, and that didn't work. Do you have Standard Architectures or some other architectures (in addition to arm64) in the Architectures build setting? – trishcode Sep 14 '20 at 18:31
  • I don't have this property on my project for some reason. – JBarros35 Sep 18 '20 at 11:51
  • @JBarros35 The VALID_ARCHS setting is not shown as of Xcode 12. You have to manually add the VALID_ARCHS setting back in as a User-Defined Setting. I included a screenshot of where to add a User-Defined build setting in my answer. – trishcode Sep 18 '20 at 14:37
  • @JBarros35 Yes, you have to manually add the VALID_ARCHS setting, and you MUST NOT use arm64 in Excluded Architectures. Excluded Architectures must be empty. – engspa12 Sep 21 '20 at 16:53
  • I had this issue and pursued the other solutions but ended up with the same issue with another architecture, i386, though the other solutions didn't help with i386. This answer helped with both! – Joshua S. Sep 25 '20 at 16:56
  • I had this issue; searching the codebase for "VALID_ARCHS" in a separate editor and removing all instances of it was very straightforward and fixed the issue for me. – fuz Oct 06 '20 at 14:24
  • I had to remove the entry from both the project and the target, actually, then it worked. – Martin Oct 14 '20 at 17:58
  • Thank you very much, I was going crazy over this bug. you saved me :)) Thanks a lot – Hamid Shahsavari Dec 10 '20 at 19:22
  • Thanks! Hours struggling. For me worked excluding arm64 for simulator and removing VALID_ARCHS (both things). – Teofilo Israel Vizcaino Rodrig Apr 22 '21 at 00:13
44

Xcode 12.3

I solved this problem by setting Validate Workspace to Yes

enter image description here

RunesReader
  • 6,769
  • 1
  • 12
  • 12
  • Solved my issue. Easiest fix! I'm glad this is resolved, but can someone explain how this fixes the issue? – njdeveloper Dec 30 '20 at 20:21
  • I had the issue with UI Tests and KIF library (it's an Xcode Unit Test using KIF). I tried all the other solutions and nothing worked until I enabled the "Validate Workspace" just for those Unit Tests.. thanks! – Lluis Gerard Feb 01 '21 at 14:03
  • This is the only solution that worked for me, however it does keep a "Target Integrity" warning in the debugger. – Richard Witherspoon Feb 11 '21 at 16:11
  • After trying all other solutions over last few days with no success, this one worked for me on my Xcode 12.2. – zeeshan Mar 08 '21 at 20:17
  • This solved my issue with a React Native project on Xcode 12.5.1. Thakn you! – Brian Aug 03 '21 at 19:11
  • 2
    What is it supposed to do? Why does it work? Preferably, [update your answer](https://stackoverflow.com/posts/65306476/edit). (But ***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today.) – Peter Mortensen Sep 11 '21 at 17:31
37

Hidden Gem in all these answers

I had changed "Excluded Architectures" in my target for the main project, but not for the PODS project. Truly hidden gem. I have been with this problem for weeks now. Excluding arm64 in PODS PROJECT

Tomas Ward
  • 392
  • 3
  • 15
  • 1
    Will this affect the build in production for some devices? – Mohamed Abdou Oct 05 '21 at 14:51
  • @MohamedAbdou arm64 is used for physical devices, so I assume there might be a conflict when trying to simulate it on a real iPhone. Either way, you could try it as is, and in any case, you remove arm64 as an Excluded Architecture. For actual production and release, I suggest you simulate it successfully on both physical and virtual devices and use those settings for the release. – Tomas Ward Oct 05 '21 at 14:55
  • not perfect answer either, now your project doesn't compile on M1 & simulator, because all pods are excluded – Erkki Nokso-Koivisto Jan 10 '22 at 14:33
  • Remember to set excluded archs for the project and not the targets so that all targets inherit the excluded archs setting – Pranav Kasetti Apr 22 '22 at 12:14
32

Easy fix

  1. Right click on xcode in Applications folder
  2. Get info
  3. Select "Open using Rosetta"

Run.

Xcode get info

8HP8
  • 1,184
  • 2
  • 12
  • 15
30

After trying and searching different solutions, I think the most safest way is adding the following code at the end of the Podfile

post_install do |pi|
   pi.pods_project.targets.each do |t|
       t.build_configurations.each do |bc|
          bc.build_settings['ARCHS[sdk=iphonesimulator*]'] =  `uname -m`
       end
   end
end

This way you only override the iOS simulator's compiler architecture as your current cpu's architecture. Compared to others, this solution will also work on computers with Apple Silicon.

Camsoft
  • 11,230
  • 19
  • 79
  • 120
OmerTurhn
  • 316
  • 3
  • 6
29

For me the following setting worked:

Build SettingsExcluded Architectures.

I added "arm64" to both Release and Debug mode for the "Any iOS Simulator SDK" option.

Enter image description here

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Raghav
  • 7,498
  • 5
  • 74
  • 97
22

Go to Targets section, select each target and do the following:

  • Set Build Active Architecture Only to YES
  • Add Excluded Architectures and set its value to arm64 (See attached)
  • Set Active scheme (on toolbar next to project name) to any iOS Simulator
  • Clean Build folder from Product Menu and build.

enter image description here

programmer
  • 431
  • 3
  • 14
17

I found that

  1. Using Rosetta (Find Xcode in Finder > Get Info > Open using Rosetta)
  2. Build Active Architecture Only set to YES for everything, in both Project and Target
  3. (You might not need it, read comment below) And including this in the podfile:
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings["ONLY_ACTIVE_ARCH"] = "YES"
    end
  end
end

worked for me.

We had both Pods and SPM and they didn't work with any of the combinations of other answers. My colleagues all use Intel MacBooks and everything still works for them too!

Bosco Domingo
  • 181
  • 2
  • 6
  • The podfile code might not be necessary. I have found I no longer need it by some magic power when its absence would once make Xcode fail to build. As of today it is no longer in the podfile and everything still works, so FYI. "Build to Active Arch only" is still set to yes for Project and Target (for my Dev builds since that's all I do as I'm not in charge of releases, but I doubt it would break much to use it for Release builds too) – Bosco Domingo Mar 25 '21 at 10:52
  • 4
    OMG, after 4 hours of digging, your answer solved my issue! I am on a `M1 Mac` and using `CocoaPods and SPM` too. I think all above answers are for fixing CocoaPods only, but does not fix issues for SPM. And you are right, I did not actually need your step 3, just first 2 steps and it's all working! Thank you! – Daniel Hu Apr 24 '21 at 22:58
16

I solved the problem by adding "arm64" in "Excluded Architectures" for both the project target and pod target.

Xcode → Target ProjectBuild SettingExcluded Architectures → *"arm64"

Xcode → Pod TargetBuild SettingExcluded Architectures → *"arm64"

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Vader
  • 176
  • 6
16

If you have trouble in Xcode 12 with simulators, not real device, yes you have to remove VALID_ARCHS settings because it's not supported anymore. Go to "builds settings", search "VALID_ARCHS", and remove the user-defined properties. Do it in every target you have.

Still, you may need to add a script at the bottom of your podfile to have pods compiling with the right architecture and deployment target:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
     end
  end
end
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Medhi
  • 1,481
  • 13
  • 11
15

After upgrading to Xcode 12 I was still able to build for a real device, but not the simulator. The Podfile build was working only for the real device.

I deleted VALID_ARCHS under Build Settings > User-Defined and it worked! Bashing my head for some time before finding this.

Navigator
  • 221
  • 1
  • 9
14

1.Add arm64 to Build settings -> Exclude Architecture in all the targets.

Xcode ScreenShoot

2.Close Xcode and follow the steps below to open

  1. Right-click on Xcode in Finder
  2. Get Info
  3. Open with Rosetta
Martin Brisiak
  • 3,473
  • 12
  • 35
  • 49
SleepyCatZz
  • 195
  • 1
  • 3
10

Xcode 12

Removing VALID_ARCH from Build settings under User-Defined group work for me.

enter image description here

Pratik Sodha
  • 3,394
  • 2
  • 18
  • 36
10

I was having issues building frameworks from the command line. My framework depends on other frameworks that were missing support for ARM-based simulators. I ended up excluding support for ARM-based simulators until I upgrade my dependencies.

I needed the EXCLUDED_ARCHS=arm64 flag when building the framework for simulators from the command line.

xcodebuild archive -project [project] -scheme [scheme] -destination "generic/platform=iOS Simulator" -archivePath "archives/[scheme]-iOS-Simulator" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES EXCLUDED_ARCHS=arm64
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
inder_gt
  • 323
  • 5
  • 8
  • 2
    Same here. Key "problem" in this scenario is actually building for a generic destination via `-destination "generic/platform=iOS Simulator"`. This leads to building for all available architectures, which includes arm64 since Xcode 12. – Sascha Oct 14 '20 at 12:14
7

I believe I found the answer. Per the Xcode 12 beta 6 release notes:

"The Build Settings editor no longer includes the Valid Architectures build setting (VALID_ARCHS), and its use is discouraged. Instead, there is a new Excluded Architectures build setting (EXCLUDED_ARCHS). If a project includes VALID_ARCHS, the setting is displayed in the User-Defined section of the Build Settings editor. (15145028)"

I was able to resolve this issue by manually editing the project file (I could not figure out how to remove the item from the project file using Xcode) and removing all lines referring to VALID_ARCHS. After that, I am able to build for the simulator fine.

btxios
  • 7,225
  • 3
  • 8
  • 7
  • 2
    Using Xcode, VALID_ARCHS is in select Project (not Target) then `Build Setting -> User-Defined". select it and delete it. – Akshay Sep 19 '20 at 04:58
  • This solution worked for me. The solution suggested by some others didn't work as just adding value 'arm64' to the 'Exclude Architecture' field started giving some 'File Permission' error for the generated .app file. – archeopetrix Sep 21 '20 at 14:53
  • Thanks @btxios and Akshay. Worked like a charm, Its party time – Ravi Mar 03 '21 at 04:43
5

After trying almost every answer to the question and reading through Apple developer forums I found only one solution worked for me.

I am building a universal framework that is consumed in a Swift app. I was unable to build to the simulator without architecture errors.

In my framework project I have a Universal Framework task in my build phases. If this is the case for you:

  • Add the following to your xcodebuild task inside the build phase: EXCLUDED_ARCHS="arm64"

Next you have to change the following project Build Settings:

  • Delete the VALID_ARCHS user defined setting
  • Set ONLY_ACTIVE_ARCH to YES ***

*** If you are developing a framework and have a demo application as well, this setting has to be turned on in both projects.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
willhess
  • 1,184
  • 11
  • 13
5

I was facing the same issue and trying to launch a React Native app on an M1 Mac. Note that my Intel Mac with the same project worked well without this error.

What solved the problem for me was to force Xcode to open through Rosetta.

To achieve this:

Right click on Xcode in Applications folder* → Get Info → check 'Open using Rosetta' checkbox.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Raphael Payet
  • 69
  • 1
  • 5
5

Go to finder -> Applications -> Xcode -> Right click on Xcode -> Select open using rosetta

enter image description here

Hassan
  • 184
  • 2
  • 7
  • While this will allow you to build your project is definitely NOT advisable. You will be running Xcode in an x86 emulated environment. This will likely be much slower and not take advantage of your M1 processor. – MobileVet May 24 '22 at 15:20
4

In your xxx.framework podspec file, add the following configuration. Avoid a pod package that contains arm64 simulator architectures.

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
  • It worked! However this means that the Pod cannot be used in Apple Silicon based Macs? – tomacco Sep 30 '20 at 06:26
  • Is it confirmed @tomacco? – Fernando Reynoso Oct 01 '20 at 17:02
  • 2
    @FernandoReynoso I have just received an Developer Transition Kit, (ARM MacMini) will test and report later today – tomacco Oct 02 '20 at 10:50
  • @tomacco Have you been able to test it? – Houman Oct 14 '20 at 13:48
  • If multiple pod specs use `user_target_xcconfig` and the values don't match exactly, CocoaPods will emit warnings like this `[!] Can't merge user_target_xcconfig for pod targets: [... list of pods ...]. Singular build setting EXCLUDED_ARCHS[sdk=<...>] has different values.` The podspec syntax reference says this attribute is "not recommended" https://guides.cocoapods.org/syntax/podspec.html#user_target_xcconfig. So please don't use `user_target_xcconfig` for this to save many developers the trouble. – leberwurstsaft Oct 16 '20 at 07:11
  • I think this problem will be fixed later by Cocoapods – jiawei wang Oct 16 '20 at 11:02
  • not great, because user_target_xcconfig propagates to main project, and all your pods are excluded on M1 & simulator.. – Erkki Nokso-Koivisto Jan 10 '22 at 14:36
4

I was also experiencing the same issue with specific library that was installed through carthage. For those who are using Carthage, as Carthage doesn't work out of the box with Xcode 12, this document will guide through a workaround that works for most cases. Well, shortly, Carthage builds fat frameworks, which means that the framework contains binaries for all supported architectures. Until Apple Sillicon was introduced it all worked just fine, but now there is a conflict as there are duplicate architectures (arm64 for devices and arm64 for simulator). This means that Carthage cannot link architecture specific frameworks to a single fat framework.

You can follow the instruction here. Carthage XCODE 12

Then after you configure the Carthage. Put the arm64 in the "Excluded Architectures" on build settings. enter image description here

Try to run your project using simulator. Simulator should run without any errors.

vidalbenjoe
  • 885
  • 12
  • 31
4

Please, don't forget to clean the build folder after you add arm64 to excluded architecture.

  • How? By some menu command? By manually deleting files or folders? Can you elaborate? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/66270009/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Sep 11 '21 at 17:35
3

The problem here are the Valid architectures in Xcode 11. Open the project in Xcode 11 and change the Valid architectures value to $(ARCHS_STANDARD) for both your project, target and Pods. Reopen the project in Xcode 12 and build.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
user4478383
  • 328
  • 2
  • 11
  • Thank you for your mention of the pods! in my case, I had to *exclude* the arm64 architecture from the Pods project for it to work, but thanks for the hint – head in the codes Oct 27 '21 at 04:18
3

Updates: Oct 2020

You can simply set arm64 only for Debug > Simulator - iOS 14.O SDK under Excluded Architecture.

enter image description here

Sunil Targe
  • 6,927
  • 5
  • 47
  • 75
3

First, generate x86_64 for Pod projects!!!!

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ARCHS'] = "arm64 x86_64"
        end
    end
end

Second, add "x86_64" for VALID_ARCHS.

Enter image description here

I found this after trying a lot of useless answers online, and this works for me.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
YanXing Ou
  • 49
  • 2
  • I develop a custom framework. While I converting a framework to XCFramework, I got a similar error. As YanXing said, I could solve this issue by adding "arm64 x86_64" to VALID_ARCHS. My previous VALID_ARCHS values was "arm64 arm64e armv7 armv7s", and I could not build a framework for simulator. It is wired because I could build a simulator framework in the previous version. – winner.ktw Apr 20 '21 at 11:10
  • To add VALID_ARCHS, in Build Settings tab, click the + button in the top area, and select "Add User-Defined Setting". – winner.ktw Apr 20 '21 at 11:15
  • My Xcode version is 12.4 and macOS is Catalina 10.15.5. – winner.ktw Apr 20 '21 at 11:20
  • not great because VALID_ARCHS are deprecated – Erkki Nokso-Koivisto Jan 10 '22 at 14:37
3

Xcode 13.2.1, Monterey, target iOS 14.0, cocoapod 1.11.2

I had a similar issue when including LogRocket and/or Plaid -- they are xcframeworks, works fine on my local but can't be built on bitrise, I'd tried all answers above:

  • EXCLUDED_ARCHS arm64
  • setting ONLY_ACTIVE_ARCH to YES in Podfile
  • VALIDATE_WORKSPACE to YES
  • setting ARCHS[sdk=iphonesimulator*] to uname -m in Podfile

none of them works

but by specifying target iOS version or delete it would work:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
      # OR
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
    end
  end
end
rexsheng
  • 131
  • 1
  • 3
2

Issue when compiling for the simulator:

Building for the iOS simulator, but linking in an object file built for iOS, for architecture arm64

Xcode 12.1, Pod 1.9.1

My project structure

  • Main Target
  • Share Extension
  • Notification service extension
  • Submodule, Custom Framework
  • Podfile
  1. Add arm64 to Build settings -> Exclude Architecture in all the targets.

    Enter image description here

  2. Removed arm64 from VALID_ARCHS and added x86_64 in all the targets.

    Enter image description here

  3. Add following code in podfile

    post_install do |installer|
        installer.pods_project.build_configurations.each do |config|
        config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
     end
    end
    
  4. Did pod update, deleted podfile.lock, and did pod install

  5. Do a clean build.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Gokul G
  • 1,976
  • 14
  • 22
2

It worked for me when I set $(ARCHS_STANDARD) for VALID_ARCHS for Debug for Any iOS Simulator SDK. Also I have set YES for ONLY_ACTIVE_ARCH for Debug.

enter image description here

Nikaaner
  • 718
  • 10
  • 13
  • 1
    This is working for me in Xcode 12.4 -> add new user-defined VALID_ARCHS with value $(ARCHS_STANDARD) – Albi Jan 25 '21 at 08:25
2

In my case, the error was thrown by GTMAppAuth which I was using with Google sign in my Flutter project.

Solution: You have to go to that package and click YES in Build Active Architecture Only.

Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Mr B
  • 91
  • 1
  • 7
  • How do I get to the Build Settings of the GTMAppAuth package? (I have installed with swift package manager) – Konstantin Schubert Oct 31 '21 at 13:05
  • @KonstantinSchubert refer to the attached screenshot: https://drive.google.com/file/d/165gAEFXo_8btX774FgNOFVCx-QjYNO3X/view?usp=sharing Step 1: Go to Pod (below of runner) Step 2: In the middle pane, look for GTMAppAuth Step 3: click YES in Build Active Architecture Only – Mr B Nov 02 '21 at 05:00
  • This was life saving for me. – Muhammad Shehroz Sajjad May 22 '22 at 16:34
2

In my case updating CocoaPods helped:

  1. Uninstall CocoaPods if installed:

    sudo gem uninstall cocoapods
    
  2. Install CocoaPods:

    brew install cocoapods
    
  3. If you have a linking error:

    brew link --overwrite cocoapods`
    
  4. Run pod install

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
BigSt
  • 19,607
  • 4
  • 63
  • 81
1

On Build Settings search VALID_ARCH then press delete. This should work for me with Xcode 12.0.1

VALID_ARCH on build settings

Cuong Lam
  • 2,572
  • 2
  • 19
  • 18
1

In the below image, in Excluded Architectures → in debug and release tap + button → in both debug and release.

Enter image description here

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Sahil Omer
  • 133
  • 9
0

In my case:

I had four configurations (+ DebugQa and ReleaseQa). Cocoapods is used as a dependency Manager.

For DebugQa, I gathered on the device and in the simulator, and on ReleaseQa only on the device.

It helped to set BuildActiveArchitecture to "yes" in PodsProject.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
0

In my case, I was trying to run on an watchOS 7 simulator in Release mode, but the iOS 14 simulator was in Debug mode.

So simply putting both simulators in Debug/Release mode solved the problem for me!

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Cosmin
  • 5,973
  • 3
  • 25
  • 28
0

In my case: Xcode 12

I set empty values on EXCLUDED_ARCHS and set ONLY_ACTIVE_ARCH Debug = YES Release = NO Project's Build Setting

and I included this in my Podfile:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
        end
    end
end

It runs on my Simulator iPhone 8 (iOS 12) and iPhone 11 Pro Max (iOS 14) and on my device iPhone 7 Plus (iOS 13.4)

mitchy_dev
  • 17
  • 2
0

Set the "Build Active Architecture Only"(ONLY_ACTIVE_ARCH) build setting to yes, xcode is asking for arm64 because of Silicon MAC architecture which is arm64.

arm64 has been added as simulator arch in Xcode12 to support Silicon MAC.

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/SDKSettings.json

Dilan
  • 2,333
  • 7
  • 21
  • 30
Aravind
  • 49
  • 4
0

Switch Build Configuration back to Debug mode or turn on Build Active Architecture Only for both Debug and Release mode.

The reason is your library/framework doesn't support new simulator architecture ARM64 (run on Mac with an Apple silicon processor).

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
0

Add line "arm64" (without quotes) to path: Xcode* → ProjectBuild settingsArchitecturesExcluded architectures.

Also, do the same for Pods. In both cases, for both debug and release fields.

Or in detail...

Errors mentioned here while deploying to simulator using Xcode 12 are also one of the things which have affected me. Just right-clicking on each of my projects and showing in finder, opening the .xcodeproj in Atom, then going through the .pbxproj and removing all of the VALIDARCHS settings. This was is what got it working for me.

I tried a few of the other suggestions (excluding arm64, Build Active Architecture Only) which seemed to get my build further, but ultimately leave me at another error. Having VALIDARCH settings lying around is probably the best thing to check for first.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Sohaib Aslam
  • 1,050
  • 15
  • 22
0

Only add Any iOS Simulator SDKx86_64 to Project's Build SettingsVALID_ARCHS works for me.

Xcode version: 12.1 (12A7403)

Enter image description here

If your project includes some frameworks that don't support x86_64.

  • You can add these framework names(xxx.framework) to TargetBuild SettingsExcluded Source File NamesDebugAny iOS Simulator SDK.
  • And then modify the Framework Search Paths to delete the paths of these frameworks for DebugAny iOS Simulator SDK.

These two settings can avoid Xcode to build and link these frameworks in simulator mode.

Enter image description here

Enter image description here

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Daemonson Dong
  • 162
  • 3
  • 11
  • If you have remove the frame work paths how you can access the properties from framework... – Naresh Sep 22 '21 at 14:45
  • This one actually helped me in another context. The "Exclude source File Names" option has been helpful. With actual Framework names in the screenshots; it would have been better! – herve Oct 06 '21 at 17:21
0

I understand the issue with arm64 and Xcode 12 and I was able to resolve build issues by excluding the arm64 architecture for iPhone Simulator or by setting ONLY_ACTIVE_ARCH for Release scheme. However I still have problems to push my framework using pod repo push.

I found out that setting s.pod_target_xcconfig in my podspec does not apply this setting to dependencies defined in the same podspec. I can see it in the dummy App project that Cocoapods is generating during the validation. Cocoapods validation is running release scheme for simulator and this is failing when one or more dependencies doesn't exclude arm64 or is not set to build active architecture only.

A solution could be to force Cocoapods to add post install script while validating the project or let it build Debug scheme, because the Debug scheme is only building active architecture.

I ended up using Xcode 11 to release my pod to pass the validation. You can download Xcode 11 from developer.apple.com, copy it to Applications folder as Xcode11.app and switch using sudo xcode-select --switch /Applications/Xcode11.app/Contents/Developer. Don't forget to switch back when done.

  • Is "pod repo push" literal or not? – Peter Mortensen Sep 11 '21 at 17:30
  • I'm pushing to custom repository, so the command is `pod repo push {repository name} {path to podspec file}` Anyway I commented out the validation procedure in cocoapods source file as a workaround. Instead of this I am doing the validation myself by referencing the published lib in my project. – Rudolf Kopřiva Sep 13 '21 at 13:56
0

After excluding arm64 I always got ARCHS[@]: unbound variable. For me the only solution was to add x86_64 to the target build setting as mentioned here Problems after upgrading to Xcode 12:ld: building for iOS Simulator, but linking in dylib built for iOS, architecture arm64 You also might remove the exclude arm64 you added before.

Harry
  • 31
  • 4
0

I was trying to build xcFramework when I faced this issue. Nothing was helping, but I managed to resolve this with lipo and am sharing my script:

OUTPUT_DIR_PATH="${PROJECT_DIR}/XCFramework"

function archivePathSimulator {
    local DIR=${OUTPUT_DIR_PATH}/archives/"${1}-SIMULATOR"
    echo "${DIR}"
}

function archivePathDevice {
    local DIR=${OUTPUT_DIR_PATH}/archives/"${1}-DEVICE"
    echo "${DIR}"
}

function archive {
    echo "▸ Starts archiving the scheme: ${1} for destination: ${2};\n▸ Archive path: ${3}.xcarchive"
    xcodebuild clean archive \
    -project "${PROJECT_NAME}.xcodeproj" \
    -scheme ${1} \
    -configuration ${CONFIGURATION} \
    -destination "${2}" \
    -archivePath "${3}" \
    SKIP_INSTALL=NO \
    OBJROOT="${OBJROOT}/DependentBuilds" \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty
}

# Builds archive for iOS simulator & device
function buildArchive {
    SCHEME=${1}

    archive $SCHEME "generic/platform=iOS Simulator" $(archivePathSimulator $SCHEME)
    archive $SCHEME "generic/platform=iOS" $(archivePathDevice $SCHEME)
}

# Creates xc framework
function createXCFramework {
    FRAMEWORK_ARCHIVE_PATH_POSTFIX=".xcarchive/Products/Library/Frameworks"
    FRAMEWORK_SIMULATOR_DIR="$(archivePathSimulator $1)${FRAMEWORK_ARCHIVE_PATH_POSTFIX}"
    FRAMEWORK_DEVICE_DIR="$(archivePathDevice $1)${FRAMEWORK_ARCHIVE_PATH_POSTFIX}"

    echo "Removing ${FRAMEWORK_SIMULATOR_DIR}/${1}.framework/${1}"

    if lipo "${FRAMEWORK_SIMULATOR_DIR}/${1}.framework/${1}" -verify_arch "arm64"; then
        echo "Removing arm64"
        lipo -remove "arm64" -output "${FRAMEWORK_SIMULATOR_DIR}/${1}.framework/${1}" "${FRAMEWORK_SIMULATOR_DIR}/${1}.framework/${1}"
    fi

    xcodebuild -create-xcframework \
               -framework ${FRAMEWORK_SIMULATOR_DIR}/${1}.framework \
               -framework ${FRAMEWORK_DEVICE_DIR}/${1}.framework \
               -output ${OUTPUT_DIR_PATH}/xcframeworks/${1}.xcframework
}

echo "#####################"
echo "▸ Cleaning the dir: ${OUTPUT_DIR_PATH}"
rm -rf $OUTPUT_DIR_PATH

DYNAMIC_FRAMEWORK="${PROJECT_NAME}"

echo "▸ Archive $DYNAMIC_FRAMEWORK"
buildArchive ${DYNAMIC_FRAMEWORK}

echo "▸ Create $DYNAMIC_FRAMEWORK.xcframework"
createXCFramework ${DYNAMIC_FRAMEWORK}
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
0

I had the same issue for the simulator/SwiftUI preview with the following warnings:

ld: warning: ignoring file Pods/.../X.xcframework/ios-arm64_armv7/X.xcframework/X, missing required architecture x86_64 in file Ignoring file Pods/.../X.xcframework/ios-arm64_armv7/X.xcframework/X (2 slices)

I had recursive path $(SRCROOT) in the Framework Search Path in my project settings. After removing it, the project built without the error.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Tibidabo
  • 21,193
  • 4
  • 88
  • 86
0

In our case it was an error in a Jenkins build:

Frameworks/release' xxx/Library/Developer/Xcode/DerivedData/xxx-cuytrcyjdlfetmavpdonsknoypgk/Build/Products/Debug-iphoneos/AppsFlyerLib.framework/AppsFlyerLib(AFSDKDevice.o), building for iOS, but linking in object file built for Mac Catalyst, file 'xxx/Library/Developer/Xcode/DerivedData/xxx-cuytrcyjdlfetmavpdonsknoypgk/Build/Products/Debug-iphoneos/AppsFlyerLib.framework/AppsFlyerLib' for architecture arm64

We fixed it with sudo gem update cocoapods.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Nike Kov
  • 11,754
  • 6
  • 65
  • 104
0

I got the same error after switching to Macbook Pro M1 App Silicon. Solution that worked for me:

  • delete the Podfile.lock
  • run pod install that's it.
Miniapps
  • 294
  • 3
  • 3
0

Xcode Version 13.2.1 and macOS Monterey 12.0.1

Almost everybody is facing the same issue with old projects and pods after switching to new M1 chip system.

"in /Users//Desktop/_iOS_app/Pods/iOS/framework/(CLSInternalReport.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/y/Desktop/_iOS_app/Pods/iOS/.framework/for architecture arm64"

I have come to a solution which is working perfectly.

First thing first, to all the developer who are suggesting exclude arm64 for your project will work yes it will compile but after installation when you try to open it, it will show a popup with the message, "the developer of this App needs to be update it to work with this version of iOS". This is because as per apple "In iOS 11 and later, all apps use the 64-bit architecture" and if you exclude arm64 for your project it will not open App on iOS 11 and later.

App will not open in iOS 11 and later if exclude arm64 and will show this popup

So instead of selecting whole project only excluded architectures for the simulator to arm64.

Steps: On top of project files, Select target > build setting > architecture > excluded architecture. now add select "any iOS simulator SDK" and give it a value arm64.

See the image below for refrence.

only select "any iOS simulator SDK" in excluded architecture instead of excluding it for whole project.

-1

In my case it's working 100%. Try this:

I have a temporary solution.

You just follow the image.

  • Double click architecture and select Other and Remove all lines

  • Add two things arm7s and arm7

  • Run your physical device on the iPhone, not the simulator

  • Enjoy...

Example image

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124