Xcode 12 Apple M1 arm64 - Designable error: "wrong architecture"

10.2k views Asked by At

My current project throws IBDesignable errors when using Interface builder on an apple Silicon based machine.. i tried excluding arm64 architecture for debugging, as well as some other hints i found on the internet, but no success at all..

the project builds fine on simulators and on real devices as well, but interface builder seems to be unable to draw those IB Designables correctly on arm64 based systems...weird.

hope someone knows which flag to set to correct this error..bc it's driving me crazy :/

Error:

"dlopen(MYAPP.app, 1): no suitable image found. Did find MYAPP.app: mach-o, but wrong architecture"

Hope you guys can help me out, i know it's part of early adopter issues, but this has to be solvable some way!?

5

There are 5 answers

6
Crocobag On BEST ANSWER

Update

XCode 13 solved the issue on M1. No need for additional setup in Build settings.

enter image description here

Those solution were very hacky and could also be interfering with the project health. I suggest to anyone who tried those solution to discard any changes as soon as possible before being forgotten.

6
dnpp On

Same here. Xcode 12.4, macOS 11.2 on M1 MacBook Air.

Normally, InterfaceBuilder try to find binaries from: ~/Library/Developer/Xcode/DerivedData/[...]/Build/Products/${Configuration}-iphonesimulator

but on M1 Mac, InterfaceBuilder find here: ~/Library/Developer/Xcode/DerivedData/[...]/Build/Products/${Configuration}-iphoneos

I guess this is Xcode's bug...

As you know, ${Configuration}-iphoneos is for iOS devices. not for Simulator. and InterfaceBuilder really needs artifacts for iOS Simulator.

Here is simple and not-so-good solutions:

  1. Build for some iOS Simulator
  2. cd ~/Library/Developer/Xcode/DerivedData/[...]/Build/Products/
  3. cp -r ${Configuration}-iphonesimulator ${Configuration}-iphoneos
  4. restart Xcode

finally I could fix @IBDesignable previews. but I couldn't recommend this solution very much...

(Additional below)

I wrote workaround shellscript: https://gist.github.com/dnpp73/4f9c12ad96909355a39b99e22e42eb14

(One More Additional below)

seems fixed on Xcode 13 beta. nice work Apple Interface Builder Team!

0
Smartcat On

I had this problem on Xcode 14.0 with my M1 Mac. My code had some IBDesignables for UIView to expose cornerRadius, borderWidth, and borderColor as a UIView extension. Xcode was throwing up the warnings described in this thread, and warning of instability to render the storyboard too.

My app's deployTarget was 15.0, but after reading the comment above about how deployTarget needs to be at least 13.0 to solve the problem, I discovered that it was my cocoapods that could have a lower deployTarget!

So by adding the below to by Podfile to force all my Cocoapods to have at least iOS 13 deploy target, all those storyboard warnings about IBDesignables and general instability to render and archtecture mismatch went away! (I'm showing also ONLY_ACTIVE_ARCH force to NO but I already had this one in place - so though that wasn't the fix, per se, I think you'll want it too).

Don't forget to then delete your Pods dir (and DerivedData) and do a pod install.

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
      config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
    end
  end
end
0
Robert Fogash On

Same issue on XCode 14.3

This is how I solved id:

  1. Set the target architecture to arm64
  2. Set the target exclude architecture x86_64
  3. Clean build folder (Product -> Clean build folder)
  4. Restart XCode
4
deanWombourne On

Here's how I've fixed it on my project.

  • All my IBDesignable views are in their own framework, which has no other dependencies (I already had this setup)

  • In Build Settings, change "Build Active Architecture Only" to "No" for debug builds.

  • In Build Settings, change "Supported Platforms" to include "macxos" as well as the iOS defaults, for debug builds

  • Frustratingly, even though I don't have any dependencies on the framework with my IBDesignable views in, I was getting some errors related to dependencies of my app - which I fixed by this answer: https://stackoverflow.com/a/42765750 which disabled "ONLY_ACTIVE_ARCH" for my cocoapod dependences.

  • In your storyboard you'll need to trigger a rebuild by choosing Editor->Refresh all views.

Screenshot of project settings