Failed to load test bundle on Mac M1, found x86_64, required arm64

1.8k Views Asked by At

I'm running Xcode 13.4.1 on an M1 and trying to run the test bundle.

What I did:

  • Created a target whose configuration includes the standard architectures as well as x86_64.
  • Excluded architecture arm64 for that target.
  • Made sure 'Build Active Architecture Only' is set to No for this target.

The project builds successfully on M1 but the tests immediately fail with the error: System: Failed to load the test bundle ... mach-o file but is an incompatible architecture (have ‘x86_64’, need ‘arm64’)

I checked the build log and indeed the linker command appears to target x86_64, it's at the start of the command: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-ios11.0-simulator ...

But I thought this is what I'm supposed to be doing as I'm running this on my M1 simulator. If I try to exclude arm64 my project doesn't build anymore (I understood this has to do with the way some pods in my dependencies are running, requiring arm64 to be excluded).

Is there a way to make the project build for M1 but the tests to also run?

I saw similar questions but nothing matched this case and solutions didn't work.

2

There are 2 best solutions below

0
Jin On

Xcode: 14.0.1 Cocoapods: 1.12.0 "debugserver is x86_64 binary running in translation, attached failed"

when project is Macos Monterey, i make it working by

  1. toggle on Rosetta,
  2. set excluded Architecture arm64
  3. update pod file with
    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

After upgrade to Macos Venture, it is not working anymore. running unit test will report, "Failed to load test bundle on Mac M1, found x86_64, required arm64". following steps can help you solve the issue

  1. toggle off Rosetta
  2. remove "excluded Architecture arm64" in xcworkspace
  3. remove all dependency "excluded Architecture arm64"
       post_install do |installer|
         installer.pods_project.targets.each do |target|
           target.build_configurations.each do |config|
          config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = ""
           end
         end
       end
0
Manish Kundu On

If it's M1 then you need to force Xcode to run under Rosetta

  1. Quit Xcode if it is running.
  2. Use Finder to locate Xcode. app in the Applications folder of your Mac.
  3. Right click Xcode.app and select 'Get Info'
  4. Click the 'Open using Rosetta' check box.
  5. Restart Xcode. It will now be running in emulation and will be slower than usual.