22

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

blendstylez
  • 341
  • 3
  • 16

5 Answers5

8

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!

dnpp
  • 81
  • 3
  • I'll try this out the next time the bug happens. I actually "solved" it by just copy-pasting all the designable code into my own code (manual installation instead of Cocoapods), but this would not work for bigger libraries – aheze Feb 05 '21 at 16:24
  • While the most correct answer would be for Apple to fix this in Xcode, I think this answer is the best. We tried many build settings fixes and none worked for us. This one works! Thank you! – stevekohls Apr 22 '21 at 18:29
  • Yes! Thank you so much! This works for me in Xcode 12.4, macOS 11.2.3 on M1 Mac mini. – Josh Brown Apr 22 '21 at 18:34
  • run your , but, Terminal return that >find: -regextype: unknown primary or operator – shaohua Apr 23 '21 at 12:51
  • oh sorry, this workaround script needs `GNU find`. The default `find` command on the Mac is the `BSD` version. you can use by `brew install findutils`. also you may need to set the `PATH`. – dnpp Apr 24 '21 at 08:41
  • yes, it works. very very very very very thanks – shaohua Apr 25 '21 at 09:09
7

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

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • I think there must be one more step that needs to be taken in some cases- I fought this same issue for a while before I found this post, and your solution fixed it for me. Then, I ended up having to go back and redo/undo a whole bunch of cocoapod things that resulted in me basically putting all my settings back to default (breaking my IBDesignables again). Going back through your solution didn't fix it this time, though, so there must be something I had tweaked before finding this on stackoverflow that was also necessary- no idea what, though. – NickGlowsinDark Jan 23 '21 at 15:54
  • Hey, I returned the M1 mac so can't help anymore, sorry :( My fix only worked sometimes as well, but each time I restarted Xcode and cleaned the project and it fixed itself. Not sure how/why. – deanWombourne Jan 25 '21 at 11:50
  • finally i am able to try this solution attempt myself, i had to return my M1 book as well..now i finally got my replacement..but unfortunately this does not solve my IBDesignable issue right now. imo this is weird bc xcode should be ready to work properly on their own machines..but obviously it does not (yet) – blendstylez Feb 07 '21 at 09:29
  • 1
    @deanWombourne getting rid of M1 seems as the best solution, it's not ready and stable product – Isaak Osipovich Dunayevsky Aug 23 '21 at 13:27
3

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.

Olympiloutre
  • 2,268
  • 3
  • 28
  • 38
  • indeed true, apple finally fixed this! 9 months later :p (y) – blendstylez Sep 23 '21 at 12:38
  • Eventually they would have fixed it. They own the chip, they'll do whatever it takes to make it work fine and take precedence over intel's ones. – Olympiloutre Sep 23 '21 at 15:55
  • 4
    I'm still getting a weird error in Xcode 13. A new issue? file:///Users/shimak/Documents/Experiment/B/B/Base.lproj/Main.storyboard: error: IB Designables: Failed to render and update auto layout status for ViewController (BYZ-38-t0r): dlopen(B.app, 0x0001): tried: '/B' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRootB.app' (no such file), 'B.app' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/usr/lib/B' (no such file) – Shimak Oct 02 '21 at 18:21
  • wild guess but did you change your Build settings in the past? hint: the message `(have 'x86_64', need 'arm64')`. Just a wild guess noone gets mad if its not the issue ;) – Olympiloutre Oct 02 '21 at 22:06
  • yes, to support new OS changed active architecture and exclude architecture. Is changed back to default values still same issue here – Shimak Oct 05 '21 at 18:57
  • 1
    I still have this problem on on Xcode 13. After reading the logs, I have noticed that the command is using target `x86_64-apple-ios12.1-simulator`. It seems there is no arm64 target for the SDKs < 13. If your deployment target is 12 or lower, Xcode won't build arm64. Once I have changed deployment target to iOS 13, correct architecture was selected. – Sulthan Jan 01 '22 at 23:34
2

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
Smartcat
  • 2,834
  • 1
  • 13
  • 25
2

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