3

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.

Frankie Simon
  • 721
  • 1
  • 7
  • 14
  • You need to run test with Rosetta : try [this answer](https://stackoverflow.com/a/73175609/13944750) even if badly rated. – Ptit Xav Sep 21 '22 at 11:44
  • @PtitXav I realize this will make the tests run but it's also a very "total" way of handling it - everything you build and run in Xcode will then go through Rosetta until you toggle this off. I am hoping to find a valid configuration that resolves it without losing the edge of Xcode on M1 (mainly build time). – Frankie Simon Sep 22 '22 at 11:59
  • May be a stupid question : why do you want to build for iOS x86 simulator ? – Ptit Xav Sep 22 '22 at 13:03
  • 1
    May be you can try to set the Rosetta flag on the simulator application inside the xCode app, xCode will continue running M1 to compile while simulator is running x86. – Ptit Xav Sep 22 '22 at 13:52
  • I tried this but somehow got the same error. I don't want to guess the behavior but possibly it has its own mean of defining whether to run it with Rosetta or not. – Frankie Simon Sep 22 '22 at 18:02

2 Answers2

0

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
Jin
  • 665
  • 1
  • 7
  • 15
0

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.