Xcode building for iOS Simulator, but linking in an object file built for iOS, for architecture 'arm64'
Asked Answered
G

66

923

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.

Gamages answered 26/8, 2020 at 23:40 Comment(7)
This is worked for me: stackoverflow.com/questions/24924809/…Cockiness
Check out the article: milanpanchal24.medium.com/…Mollie
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 CLISwope
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 appDempstor
https://mcmap.net/q/16649/-building-ionic-cordova-app-for-ios-on-m1-mac This worked for me. It may work for you as well.Leverett
See this comprehensive answer for a detailed explanation of platform vs architecture, fat binary vs xcframework, ways of inspecting binaries, differences of the flags, Apple's recommendation and more.Anabelle
Note that if you are using XCode 14.3 or higher that the Open using Rosetta has been removed. If you run into build or deployment issues regarding running on a Simulator when building on an M1 or M2 Apple Silicon using these versions of XCode then https://mcmap.net/q/16650/-transfer-to-apple-m1-xcode-shows-an-error-quot-39-firebasecore-firebasecore-h-39-file-not-found-quot-and-quot-could-not-build-objective-c-module-39-firebase-39-quot may be of use. Targeting Rosetta Simulator may be required if your build contains libraries that do not yet provide XCFrameworks that support running on both x86_64 and arm64 architecturesAisha
T
1314

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
    
Todhunter answered 18/9, 2020 at 11:41 Comment(29)
@DominatorVbN So all dependancies for a Podspec has to exclude right?Empyrean
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.Pope
@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.Todhunter
It's working in the device & getting error in Simulator.Zapata
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.Noah
I am getting building for iOS Simulator, but linking in object file built for macOS, for architecture x86_64. How to fix it?Brittabrittain
Note: You have to repeat step one for every scheme you haveQuentin
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" guides.cocoapods.org/syntax/podspec.html#user_target_xcconfigKaren
I suggest checking out https://mcmap.net/q/16651/-xcode-12-build-target-in-wrong-order-for-simulatorSnakebird
Thank you for your answer! Could you explain why this is required?Bristletail
@WojciechKulik https://mcmap.net/q/16485/-xcode-building-for-ios-simulator-but-linking-in-an-object-file-built-for-ios-for-architecture-39-arm64-39 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.Todhunter
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 dependenciesLiquorish
This worked for me. I had multiple targets. So Excluded Architectures added to the "Project", not to the "Targets"Shackelford
@jiaweiwang what about the ONLY_ACTIVE_ARCH solution that I have mentioned here: https://mcmap.net/q/16485/-xcode-building-for-ios-simulator-but-linking-in-an-object-file-built-for-ios-for-architecture-39-arm64-39?Protozoon
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://mcmap.net/q/16485/-xcode-building-for-ios-simulator-but-linking-in-an-object-file-built-for-ios-for-architecture-39-arm64-39Regeneracy
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.Hepatic
man, you saved my day. Anyone who comes here from react native and have this github.com/wix/Detox/issues/2554 issue, this solution works perfectly.Skull
Besides the project I had to do this inside the project folder -> CordovaLib.xcodeproj file to make it work.Juvenal
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.Purdah
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.Uninterested
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.Kalvin
I'm able to build & run on Simulator on Apple Sillicon, but unit tests for internal frameworks do not run with thisPerambulator
I am not using pod in my objective-c project. Facing the error. But the above solution not worked in 12.5.1.Norvin
Xcode - 13 ??? just try adding excluded-architecture - both debug and release to : arm64, & build excluded architecture to: yesSundry
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?Lignin
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 showDoersten
for tvOS you'd need to use the following: config.build_settings['EXCLUDED_ARCHS[sdk=appletvsimulator*]'] = 'arm64' But in my situation the library was one I had in my project that wasn’t integrated with Cocoapods because it’s private from a 3rd party vendor so I had to manually update to a newer library.Cordero
Encountered an issue where 'PrivatePod' module was not found for 'arm64' when compiling for iOS simulator on an Intel machine using Xcode 14. Solved it by excluding 'arm64' for simulator builds in the .podspec: ``` spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } ``` This tells CocoaPods to exclude 'arm64' when building for the simulator. Useful for Intel Macs. Hope this helps others!Phung
Thank you! Adding iOS Simulator SDK with value arm64 inside Excluded Architecture solved my problem.Antisocial
P
286

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.

Protozoon answered 30/9, 2020 at 14:33 Comment(9)
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.Brisling
Would not building only the active architecture cause issues with release builds during App Store/TestFlight submission?Lolalolande
@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.Protozoon
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. stackoverflow.com/questions/65364886/…Exertion
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'Norvin
@Norvin 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.Protozoon
@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.Norvin
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.Stogner
SHOULD BE: spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } spec.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }Soothsayer
O
164

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

Ormond answered 27/8, 2020 at 18:58 Comment(6)
I was testing on Release mode so I had to add it to Release tooSawbuck
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.Citrate
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.Reta
This won't work on M1 macPhotogenic
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.Sussi
I add these code lines in the pod file additionally. /////////////// installer.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" end ///////////////Kristalkristan
U
124

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

Uninterested answered 16/2, 2021 at 22:37 Comment(1)
That's true, as mangling with excluding or including architectures works solely on i386-based machines.Squat
C
78

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

Congresswoman answered 2/9, 2020 at 21:50 Comment(9)
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. :)Stavros
@Congresswoman Even after doing this i'm getting same error(xcode12 beta4), any work aroundsSid
@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.Congresswoman
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 )).Misspell
@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?Congresswoman
I don't have this property on my project for some reason.Ru
@Ru 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.Congresswoman
@Ru Yes, you have to manually add the VALID_ARCHS setting, and you MUST NOT use arm64 in Excluded Architectures. Excluded Architectures must be empty.Cresol
I had to remove the entry from both the project and the target, actually, then it worked.Fabrienne
C
73

Hidden Gem in all these answers

I had changed "Excluded Architectures" in my target for the main project, but not for the PODS project. It is a truly hidden gem. I have been with this problem for weeks now.

Excluding arm64 in PODS PROJECT

Cinquecento answered 29/9, 2021 at 15:22 Comment(5)
Will this affect the build in production for some devices?Relay
@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.Cinquecento
not perfect answer either, now your project doesn't compile on M1 & simulator, because all pods are excludedStogner
Remember to set excluded archs for the project and not the targets so that all targets inherit the excluded archs settingIinden
Actually it will given error in production when you test it on real device. It will show error "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" so if you exclude arm 64 for the main project you will not be able to open the app on real device. So to fix this you just have to exclude the arm64 for simulator only, it will work on all the machines including M1 or M2.Absenteeism
S
52

Easy fix

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

Run.

Xcode get info

Sharpshooter answered 1/5, 2021 at 17:28 Comment(4)
not great, now you are running Xcode on Rosetta emulator, which means your stuff runs slowStogner
This worked for me, but (probably due to my code base) iOS 14 and 15 Simulators were not working. I had to use version 13.5.Cw
This worked when the top-voted answer didn't. On older machines, things ran fine; on the new MacBook, things didn't run until doing this. If you are having issues with a newer Mac, this may be what you need, instead of excluding architectures. See also, https://mcmap.net/q/16653/-building-for-ios-simulator-but-linking-in-object-file-built-for-iosTope
It appears this no longer works as of Xcode 14.3. I have both 14.2 and 14.3 installed at the moment. The former has the "Open using Rosetta" option. The latter does not.Corruptible
A
52

Preface

When you build an app, you build it for a specific 'platform' and 'CPU Architecture' combination.

iOS Platforms:

  • iOS device "generic/platform=iOS"
  • Simulator "generic/platform=iOS Simulator"

Note: There a whole lot more platforms. For brevity I’m just focused on iOS platforms. Otherwise there are macOS, watchOS, tvOS, visionOS platforms.

CPU Architectures:

  • arm64
  • x86_64

This is because a macOS vs iOS vs iOS simulator will use different libraries. See How does building for iOS device and simulator actually differ?

And different CPU Architectures use different CPU instructions.

This ultimately means the built binary and the environment (device/simulator) you're running it in, will need to match. Otherwise some system libraries won't exist on the operating system, or the CPU instructions can't get processed.

Where are these settings and who changes them?

The configuration for this is in Xcode Build Settings. They affect the flags sent to the compiler. Usually Xcode does things correct and you don’t need to make any adjustments. In certain cases it doesn’t or someone (app creator, library creator, library consumer, package manager i.e. someone who makes changes into the Podfile) has tweaked these settings in a way that things get misaligned.

Will you always be building for one combination?

No. If you're using a Release config, then you'll end up archiving your product for BOTH arm64 and x86_64 architectures.

During the archive process (often in your CI/CD) then things will fail because the simulator architectures are selected as well.

Yet a 'Debug' builds onto your physical devices won't attempt to build for a different platform or architecture. It's because it prioritizes 'development speed' over 'complete correctness'.

The default Xcode ONLY_ACTIVE_ARCH settings for this are:

enter image description here

I have an Intel MacBook. If I don't exclude any architecture and platform, what will happen?

  • If you're building a debug config, then it will only build for the CPU architecture of the destination's platform. Meaning:

    • If you're building into your iPhone, you'll just need to support ARM64
    • If you're building into a simulator, you'll just need to support X86_64
  • If you're building a release config, then it will:

    • Build for both platforms and all possible architectures.

I have an M1 MacBook. If I don't exclude any architecture and platform, what will happen?

  • If you're building a debug config, then it will only build for the CPU architecture of the destination's platform. Meaning:

    • If you're building into your iPhone, you'll just need to support ARM64
    • If you're building into a simulator, you'll just need to support ARM64
    • Alternatively you can enable Rosetta for Xcode. In that case if you're building into a simulator, then you need to support X86_64 as well.
  • If you're building a release config, then it will:

    • Build for both platforms and all possible architectures.

Why is it different for Release builds?

During active development, you want to build things fast. It doesn't make sense for you to actively build architectures you don't need to use. That means if you're building into a device, then you only want to build for that platform-architecture combo. You don't want to build the other combinations.

However if you're releasing it — for others. Then because you don't want to limit/dictate how they build your app, then you have to build for all possible combinations and make sure your framework compiles for all of them.

For an app it may make less sense to make an archive for the simulator platform, however for a framework, your consumer is another developer. That developer will be building your framework into a simulator and into a real device. Hence you need to support both platforms and architectures.

Is CocoaPods the source of the problem?

It depends. If the pod has excluded a certain architecture, and you're trying to build for that architecture, then you have to ask the pod owner to not excluded it.

Otherwise if all of your pods are supporting the given platform/architecture that you're trying to build for, then it's a problem from within the code you you wrote yourself in your host app.

Solution

Update pre-compiled libraries with Apple silicon support

If the library named in the error message is from a vendor, see Update pre-compiled libraries from vendors. If you have source code for the library, rebuild the library as an XCFramework with support for the simulator on Apple silicon. To learn how to build an XCFramework, see Creating a multiplatform binary framework bundle.

Update pre-compiled libraries from vendors

If the library producing the build error is a pre-compiled library from a vendor and you don’t have the source code, contact the vendor for an updated XCFramework supporting Apple silicon. If an update isn’t available from the vendor, temporarily use the EXCLUDED_ARCHS build setting to exclude arm64 for the simulator SDK as shown in the figure below. Do not exclude arm64 for any other SDK.

From Docs

More Questions in regard to the outcome of the solution:

What happens if I exclude ARM64 for the 'iOS Simulator' Platform?

You won't be able to build into M1 simulators directly. You'd have to Use Xcode with Rosetta on M1 then. Which is a hack and is slightly slower.

What happens if I exclude X86 for the 'iOS Simulator' Platform?

You won't be able to build into Intel based simulators. Nor you'd be able to build into a simulator using Rosetta.

What happens if exclude ARM64 for the 'iOS' Platform?

You won't be able to build into physical devices. Nor archive for them. Terrible idea!

So I should exclude architectures?

Strive for your app, including all of its pre-compiled libraries, to always build for the complete set of architectures defined by the default value of the ARCHS build setting. Only use the EXCLUDED_ARCHS build setting on targets where the final released app is not using the target’s functionality on a specific architecture, such as a Mac app that only supports a legacy feature on Intel-based Mac computers. Do not modify the ARCHS build setting to achieve the same result.

Additionally in big teams, some developers may be on an M1, while some others are on older Intel based MacBooks. You never know maybe some day there'd be an M5 Macbook, that will have a distinct architecture. So it's good to be considerate of how you make your project/product/framework compatible for your own devs and your library consumers.

Do we have an iOS device with Intel X86_64?

Such a thing doesn't exist.

How do I inspect a binary?

You can use either lipo, file or dyld_info.

  • lipo and file only give you architecture information.

  • dyld_info gives you architecture, platform information and more

See comparisons a simple inspection on the terminal app binary:

enter image description here

Remember within an XCFramework there will be usually two or more binaries. Example if we just used lipo -info we have to do it on both binaries of our library:

lipo -info <path-to-binary>

On the arm64 directory within an xcframework packaging, I see:

Non-fat file: /Users/mfaani/Video.xcframework/ios-arm64/Video.framework/Video is architecture: arm64

For the sims I see:

Architectures in the fat file: /Users/mfaani/Video.xcframework/ios-arm64_x86_64-simulator/Video.framework/Video are: x86_64 arm64 

You can go into your mac's /Applications, right click; 'show Package Contents' for any app; find the app's associated binary. And then inspect it using lipo.

To be clear, a framework or an app can both be inspected with lipo. Similarly if you access the build folder on the simulator, you can inspect the binary as well.

What's the difference between an XCFramework and a FAT binary?

  • A FAT binary, is just a binary — with two (or more) architectures combined into a single binary. It's just named FAT because it's fattened. Its other names are 'multi-architecture binary' or universal binary.
  • An XCFramework is just a structured folder, a wrapper. Nothing more. That has distinct folders per platform. Within each folder there's a binary. That binary can be FAT binary or non-FAT (single architecture).

Also note, a FAT binary can be either a framework or the binary of an app. An XCFramework is just a framework. It's never the app itself.

Does my app get bloated with all the other platforms-architecture combinations I don't need?

XCFramework won't bloat app store submissions, because an archive for the iOS device will just pick up each framework from a directory that's isolated from simulator platform.

However with FAT binaries, given that it was just a single binary, you had to thin/slice the dependencies before submitting to Apple store. Otherwise you'd get the following error:

Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]'."

For more on that and its previous solution, see here

To be perfectly clear, this was an issue in pre-xcode 12. But not every project setup would face this. You'd only face this if you had some pre-compiled dependency from a vendor (who didn't share their source code, but just shared the FAT binary so you can build the app for both device and sim), otherwise if you had access to the source code then your archive wouldn't contain compilations for both architectures. It would only contain binaries for targeted architecture.

Also see this great blog post for about some more details and historical context.

What does the Folder structure of a FAT look like?

It's just a binary. It's not a folder. The binary works for two or more architectures.

What does the Folder structure of an xcframework look like?

ios-arm64
   - binary
ios-arm64_x86_64-simulator
   - (FAT) binary

If an XCFramework is made to work with mac Catalyst then the folder structure would be like:

ios-arm64
    - binary
ios-arm64_x86_64-simulator
    - (FAT) binary
ios-x86_64-maccatalyst
    - binary

For a more comprehensive list of possible platforms. See XCFrameworsk: Demonstration of creating and integrating xcframeworks and their co-op with static libraries and Swift packages

Why doesn't my vendor support ios-arm64-simulator?

It could be for a number of reasons.

  • migration effort: Often it's just that when the compiled they didn't have an M1, and it's been a long time since they've compiled and if they compile they have to make some changes. Like you have to understand it's been years that that there wasn't a need for a new architecture-platform combination. So this is new and not everyone understands it. The fact that Swift is now ABI compatible with its previous versions reduce the need for framework owners to recompile their app with every new Swift release. So they could go on years without the need to recompile...
  • limitation: The pre-compiled library depends on another pre-compiled library which isn't compiled for arm64-sim.
  • The owner of the framework doesn't have an Apple Silicon (arm64) machine. Or the person who knows about those stuff has left the company.

Any last words?

Make sure you look into ALL Project AND Target AND Pod Project AND Pod Target settings. If one of them excludes a certain architecture then you can't build your app for that architecture. Often this could be in your Podfile.

Or if the pod/framework is being compiled in a totally different repo, then the settings that you have set there, are what matters the most.

If you pay attention to the error message you get, it should be easy to navigate your way to the target that doesn't support. Once you identify the target, then you have to identify when/where it gets compiled using the notes in the two paragraphs above.

Anabelle answered 15/2, 2023 at 0:3 Comment(2)
file /path/to/executable is another option for listing the contained Instruction Set Architecture (ISA) slices.Frenchpolish
The best explanation one could find among all the answers in here! It's always better to know about the reason of the problem instead of blindly going for some code snippets to fix. Thanks!Janitor
P
48

Xcode 12.3

I solved this problem by setting Validate Workspace to Yes

enter image description here

Palliate answered 15/12, 2020 at 13:6 Comment(4)
This is the only solution that worked for me, however it does keep a "Target Integrity" warning in the debugger.Laclos
What is it supposed to do? Why does it work? Preferably, update your answer. (But without "Edit:", "Update:", or similar - the answer should appear as if it was written today.)Jadotville
The option is not showing for me, I'm on xcode 14.0.1Anabatic
@Anabatic Maybe look at developer.apple.com/documentation/technotes/…Schlock
I
46

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.

Ideation answered 25/12, 2020 at 20:43 Comment(0)
F
33

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

Frisbie answered 30/9, 2020 at 12:58 Comment(0)
E
30

As of Sep 19, 2022, none of the existing answers worked for me. Most answers suggests to exclude arm64 from build settings, after this is done, it gives fatal error: module map file not found

What worked for me is to open Xcode using Rosseta,

  1. Right click on Xcode in applications folder
  2. Get Info
  3. Check Open using Rosetta
  4. Open Xcode
  5. Open project
  6. Clean build folder
  7. Run project

By opening Xcode using Rosseta, no other build settings or configurations are needed.

This is probably not a long time solution, but for quickly addressing the issue. After upgrading to MAC OS 13.5 with Xcode 14.3.1, there is no more open with Rosseta option anymore, but you do the following to run it on Rosseta.

  1. Go to “Product” in the menu bar
  2. Destination
  3. Destination Architectures
  4. Show both
  5. Pick a simulator from the device dropdown menu that has Rosseta next to it.
  6. Run project.

References:

Enclasp answered 19/9, 2022 at 14:18 Comment(1)
I got this working as of now. There is no need to use Rosetta. It's extremely slow. Add the exclude architecture not just in the application but in the pods as well as stated in one of the replies below.Imparadise
I
26

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

Indiscernible answered 27/8, 2021 at 8:19 Comment(1)
Excluding arm64 conflicts with Facebook SDK. It wants arm64, and if arm64 is excluded, it says "Could not find module 'FBSDKCoreKit' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator"Monetmoneta
A
21

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.

Absenteeism answered 12/4, 2022 at 9:25 Comment(0)
M
19

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
Mars answered 24/9, 2020 at 9:14 Comment(0)
P
18

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"

Purnell answered 17/9, 2020 at 15:14 Comment(1)
for Xcode 14.3 this solution works, there is no option like VALID_ARCHS in Xcode 14.3Delight
B
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!

Bili answered 18/2, 2021 at 18:12 Comment(1)
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)Bili
C
16

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.

Cornered answered 17/9, 2020 at 4:54 Comment(0)
A
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
Am answered 11/1, 2021 at 10:31 Comment(0)
O
12

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
Outclass answered 6/10, 2020 at 13:32 Comment(1)
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.Yonit
A
11

Xcode 12

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

enter image description here

Apollonian answered 24/9, 2020 at 6:58 Comment(2)
Removing? Do you mean changing its value to something empty'ish?Jadotville
Yeah, Remove it from the build setting. It's worked for me.Apollonian
S
11

Starting from Xcode 14.3, simply do this. Go to Product -> Destination -> Destination Architectures and select show Both. So now you can see Rosetta simulators on your destination.

enter image description here

Sympathy answered 11/5, 2023 at 9:14 Comment(0)
C
11

On the new Mac OS to solve the problem you should run using rosetta on Xcode

go to:

Xcode -> Product -> Destination -> Destination Architectures -> Show Both

Now you will have a rosetta simulator for all of your simulators

Run your code with one of the rosetta simulators and you are good to go

Cheekpiece answered 21/8, 2023 at 11:59 Comment(1)
As noted in the previous editor's edit comment, please don't use frivolous emoji: meta.stackoverflow.com/q/378226.Transcendentalism
G
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.

Gamages answered 1/9, 2020 at 21:12 Comment(1)
Using Xcode, VALID_ARCHS is in select Project (not Target) then `Build Setting -> User-Defined". select it and delete it.Calvano
K
6

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

enter image description here

Kareem answered 16/2, 2022 at 8:28 Comment(1)
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.Charlatan
A
5

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' }
Agony answered 18/9, 2020 at 11:4 Comment(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" 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.Karen
not great, because user_target_xcconfig propagates to main project, and all your pods are excluded on M1 & simulator..Stogner
P
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.

Pentalpha answered 14/10, 2020 at 20:15 Comment(0)
D
5

Updates: Oct 2020

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

enter image description here

Dunkle answered 22/10, 2020 at 9:40 Comment(2)
Are you sure? Doesn't this mean it won't actually run on a machine with Apple Silicon?Easement
On Apple Silicon it will try to build and run with Rosetta if arm64 is excludedMash
U
5

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

You can do that by going to Menu > Product > Clean Build Folder or simply Command+Shift+K.

Unthinkable answered 19/2, 2021 at 0:10 Comment(2)
How? By some menu command? By manually deleting files or folders? Can you elaborate? Please respond by editing (changing) your answer, not here in comments (without "Edit:", "Update:", or similar - the answer should appear as if it was written today).Jadotville
@PeterMortensen Menu > Product > Clean Build Folder (Xcode 13.4.1)Bibliotherapy
A
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.

Aec answered 1/7, 2021 at 14:35 Comment(1)
duplicate to 8HP8 answerStogner
F
5

Xcode 13.2.1, macOS v12 (Monterey), target iOS 14.0, and CocoaPods 1.11.2

I had a similar issue when including LogRocket and/or Plaid -- they are xcframeworks and work fine on my local, but they 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 a target iOS version or deleting 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
Forsook answered 8/1, 2022 at 13:20 Comment(0)
B
5

Please make sure to provide the code or specific error message you are encountering, as it will help in providing a more accurate solution.

Regarding the provided information, it seems like you are trying to change the architecture of your app. To resolve this issue, you can follow the steps below:

Step 1: Open your project and navigate to the "Build Settings" tab.

Step 2: In the "Excluded Architectures" section, select "Yes" for the "Change Release" option.

Step 3: Under the "Debug" and "Release" tabs, click the "+" button and select the iOS simulator SDK.

Step 4: Choose "arm64" as the architecture for both debug and release configurations.

enter image description here

Please note that the specific steps may vary depending on your development environment and tools. If you encounter any issues or need further assistance, feel free to provide more details for a more accurate solution.

Barnyard answered 7/6, 2023 at 12:42 Comment(0)
E
4

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.

Erv answered 23/10, 2020 at 10:17 Comment(2)
What is "Pod"? CocoaPods?Jadotville
Yes Pod means CocoapodsErv
U
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.

Unripe answered 10/11, 2020 at 8:4 Comment(0)
H
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.

Handclap answered 17/9, 2020 at 10:40 Comment(0)
H
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.

Hacksaw answered 26/10, 2020 at 9:53 Comment(3)
To add VALID_ARCHS, in Build Settings tab, click the + button in the top area, and select "Add User-Defined Setting".Catchup
My Xcode version is 12.4 and macOS is Catalina 10.15.5.Catchup
not great because VALID_ARCHS are deprecatedStogner
M
2

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}
Mace answered 4/3, 2021 at 16:5 Comment(4)
What language is this script in? Where do I run it?Incomprehensive
@Roi Mulia: It looks like Bash or Z shell.Jadotville
What is "lipo"?Jadotville
@PeterMortensen just googling for "macos lipo" will guide you through answers, like ss64.com/osx/lipo.htmlMessuage
S
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

Septime answered 7/6, 2021 at 13:10 Comment(2)
How do I get to the Build Settings of the GTMAppAuth package? (I have installed with swift package manager)Tacita
@KonstantinSchubert refer to the attached screenshot: drive.google.com/file/d/165gAEFXo_8btX774FgNOFVCx-QjYNO3X/… 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 OnlySeptime
R
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

Result answered 2/8, 2021 at 14:39 Comment(0)
Z
2

Adding this to the end of my pod file fixed the error:

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 i386"
    end
  end
end
Zilla answered 24/7, 2022 at 10:18 Comment(0)
M
2

Time saving salution.

Go to -> Applications -> Xcode -> Right-click on Xcode -> click on Get Info -> Select open using rosetta.

Please make sure it is in your pod file remove this. config.build_settings['ARCHS[sdk=iphonesimulator*]'] = uname -m

[enter image description here]

if your problem is not resolved the try this also

delete all the highlighted files from your project directory and re install the pod through "pod install".

enter image description here

Meekins answered 18/1, 2023 at 4:44 Comment(0)
C
1

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

Corfu answered 29/9, 2020 at 5:43 Comment(0)
S
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

Sextain answered 8/10, 2020 at 17:30 Comment(3)
I don't find VALID_ARCH, what is this?Fettling
In Build Settings tap, click the + button in the top area, and select "Add User-Defined Setting".Catchup
Can you add the "path" (series of actions) to it?Jadotville
R
1

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

Railing answered 27/10, 2020 at 18:6 Comment(0)
V
1

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

Enter image description here

Vindictive answered 26/7, 2021 at 14:40 Comment(0)
E
1

See this tech note: https://developer.apple.com/documentation/technotes/tn3117-resolving-build-errors-for-apple-silicon Excluding the arm64 for the simulator should be a temporary solution.

Excrete answered 29/11, 2022 at 14:45 Comment(0)
B
1

I had similar problem but then I just put these lines of codes into Podfile at the bottom:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'i386 arm64'
    end
  end
end
Biting answered 18/4, 2023 at 7:51 Comment(0)
P
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.

Pepin answered 20/9, 2020 at 9:8 Comment(0)
B
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!

Bribe answered 21/9, 2020 at 8:12 Comment(0)
C
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

Corse answered 29/9, 2020 at 18:5 Comment(3)
If it's not running on silicon Mac then surely it should know not use arm64?Elidiaelie
@Elidiaelie Yes, it should have been done like that, but currently its not.Corse
What is "Silicon MAC"? Do you mean Apple M1? Or Apple silicon?Jadotville
A
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).

Aberrant answered 5/10, 2020 at 22:52 Comment(0)
B
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.

Bayreuth answered 11/10, 2020 at 6:4 Comment(0)
T
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

Tyrr answered 22/10, 2020 at 3:13 Comment(1)
If you have remove the frame work paths how you can access the properties from framework...Anthropolatry
H
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.

Howardhowarth answered 30/10, 2020 at 20:15 Comment(2)
Is "pod repo push" literal or not?Jadotville
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.Pasture
G
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.

Gause answered 24/11, 2020 at 14:6 Comment(0)
F
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.

Fatshan answered 14/7, 2021 at 13:40 Comment(0)
D
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.

Donnelly answered 27/7, 2021 at 13:23 Comment(0)
C
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.
Conjunction answered 31/1, 2022 at 14:0 Comment(0)
J
0

I didn't need to build for a simulator.

The cause for me was that I had selected an iPad under iOS Simulators in the top bar where you choose the build target - selecting a real device or just Any iOS Device (arm64, armv7) fixed the issue.

Jevons answered 15/6, 2022 at 0:21 Comment(0)
H
0

Here's the only thing that worked for me:

Add this to debug (non-release) builds:

// Speed up non-production builds by building only for the currently selected architecture
ONLY_ACTIVE_ARCH = YES

// For unknown reasons we need this to be able to compile for simulators in Apple Silicon macOS without Rosetta
VALID_ARCHS = arm64 armv7 arm64-ios-simulator

And remove all instances of customization of the EXCLUDED_ARCHS setting for all configs (debug and release), including the infamous EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64 one.

These were the tests I ran after making those changes, and everything passed, on native Apple Silicon (Xcode without Rosetta mode):

Debug Staging Release
Build & Run on Device
Build & Run on Simulator
Archive
Validated against App Store Connect N/A N/A
Hatty answered 21/12, 2022 at 5:14 Comment(0)
B
0

I've seen quite a bit of weird behavior with frameworks, I think due to changes to the simulators to support Apple silicon. My temporary workaround is, in my app/extension targets, to add "arm64" to the Excluded Architectures build setting when building for the simulator (as your preview appears to be trying to do), and setting "Build Active Architecture Only" to No for all schemes. Might be worth a try.

Bhili answered 29/12, 2022 at 10:27 Comment(0)
W
0

I faced the same issue I just set Enable Bitcode to No.

enter image description here

Whist answered 14/2, 2023 at 19:4 Comment(0)
V
0

When I encounter this error, I use a 2 years ago c static lib with Xcode 14. When I achieve with the choose "Any iOS Device(64)" and connect a iPhone 14, this error pop up. But when I connect iPhone 12, this error gone.

The root cause is the c static lib is too old and can't support iPhone 14, even it supports arm64 and you can use lipo to check which architecture a lib supported.

After I ask lib provider to download the newest Xcode and build a new release, this issue has been resolved.

Valuable answered 12/5, 2023 at 4:50 Comment(0)
D
0

For me non of the solutions worked...

I use Xcode 14

What worked was - deintegrating Cocopods, cleaning the cache, and installing it again

In the project directory run

  1. pod deintegrate ProjectName.xcodeproj
  2. then run pod cache clean --all
  3. then pod install

After cleaning and building again it worked

Drambuie answered 17/5, 2023 at 8:58 Comment(0)
H
-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

Hang answered 2/5, 2021 at 13:27 Comment(0)
C
-1

Now we just need and this to Podfile, to avoid cocoapods build arm64 link file, tested for Xcode 15 with Flutter 3.

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
Chessman answered 20/2 at 3:41 Comment(1)
Please do not post duplicate answers. There are already a few answers that show this same solution.Apotheosize

© 2022 - 2024 — McMap. All rights reserved.