Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!?

like image 779
blendstylez Avatar asked Dec 14 '20 07:12

blendstylez


3 Answers

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!

like image 72
dnpp Avatar answered Oct 19 '22 21:10

dnpp


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

like image 5
deanWombourne Avatar answered Oct 19 '22 21:10

deanWombourne


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.

like image 2
Olympiloutre Avatar answered Oct 19 '22 20:10

Olympiloutre