Resolving the “Building for iOS Simulator, but Linking in an Object File Built for iOS” Error in Xcode

Resolving the "Building for iOS Simulator, but Linking in an Object File Built for iOS" Error in Xcode

22 May 2024 Stephan Petzl Leave a comment Tech-Help

When building a project in Xcode, particularly when transitioning from Xcode 11 to Xcode 12 and above, you might encounter the error: “Building for iOS Simulator, but linking in an object file built for iOS, for architecture arm64.” This issue often arises due to architectural mismatches between your project settings and the simulator environment. Here’s a comprehensive guide to help you troubleshoot and resolve this error.

Understanding the Root Cause

The primary cause of this error is that Xcode 12+ includes support for Apple Silicon (arm64) architecture for simulators. Consequently, when building for the iOS Simulator, Xcode may attempt to link against arm64 binaries, which is not supported on Intel-based Macs.

Step-by-Step Solution

Follow these steps to resolve the error:

1. Exclude arm64 for Simulator Architecture

To prevent Xcode from attempting to build arm64 for the simulator, you can exclude this architecture in your project and Pod project settings:

  1. Navigate to the Build Settings of your project.
  2. Add Any iOS Simulator SDK with the value arm64 inside Excluded Architecture.

If you are using custom XCConfig files, add the following line:

EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64

2. Update Pod Project Settings

Repeat the above steps for your Pod project. Alternatively, you can automate this by adding the following snippet to your Podfile:

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

3. Set “Build Active Architecture Only” to Yes

Another approach is to ensure that Xcode only builds for the active architecture:

  1. Go to Build Settings and set Build Active Architecture Only (ONLY_ACTIVE_ARCH) to Yes for all configurations.

If you are using CocoaPods, you can add this to your 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"

Additional Tips

Ensure that you are using the latest versions of CocoaPods and your dependencies. Sometimes, simply updating can resolve the issue as vendors may have provided support for the new architecture.

Leveraging Repeato for Efficient Testing

While resolving such build issues is crucial, maintaining high-quality standards through continuous testing is equally important. This is where Repeato comes in handy. Repeato is a no-code test automation tool for iOS and Android that allows you to create, run, and maintain automated tests swiftly.

With Repeato, you can:

  • Quickly edit and run tests, thanks to its computer vision and AI capabilities.
  • Delegate test automation tasks to non-technical colleagues or QAs, freeing up developers to focus on creating great products.

Explore more about Repeato and how it can streamline your testing process by visiting our documentation and blog sections.

By following the steps outlined in this guide and leveraging tools like Repeato, you can ensure a smoother development and testing workflow, ultimately leading to a more robust and reliable application.

Like this article? there’s more where that came from!