xcodebuild fails with #Preview macro with Xcode 15.0
Asked Answered
B

3

8

I noticed that in Xcode 15.0, xcodebuild command to archive the app fails unless I remove the #Preview macro from the app.

$ xcodebuild archive -scheme <Your Scheme> -sdk iphoneos -allowProvisioningUpdates -archivePath build.xcarchive

and the error is:

{
  "kind": "finished",
  "name": "compile",
  "pid": 42409,
  "output": "<unknown>:0: warning: compiler plugin not loaded: '\/Applications\/Xcode-15.0.0-Release.Candidate.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/usr\/bin\/swift-plugin-server; fai
led to initialize\n\/Users\/xyz\/Dev\/experiments\/fastlane-test\/fastlane-test\/ContentView.swift:22:1: error: external macro implementation type 'PreviewsMacros.SwiftUIView' could not be found for macro
'Preview(_:body:)'\n#Preview {\n^\nSwiftUI.Preview:2:41: note: 'Preview(_:body:)' declared here\n@freestanding(declaration) public macro Preview(_ name: String? = nil, body: @escaping @MainActor () -> View) = #ex
ternalMacro(module: \"PreviewsMacros\", type: \"SwiftUIView\")\n                                        ^\n",
  "process": {
    "real_pid": 42409
  },
  "exit-status": 1
}
** ARCHIVE FAILED **

How to reproduce:

  1. Create a brand new app project with Xcode 15.0 RC
  2. Run the above command

If I comment out the default #Preview statement in the ContentView.swift, the same command passes flawlessly. What am I missing?

Brawny answered 16/10, 2023 at 7:21 Comment(6)
Xcode 15.0.1 has shipped so I tried with it but the same result. I found "rosetta error: Failed to open libRosettaRuntime" message in the log by the way. Does that sound related? I'm using the M1 macBrawny
Seeing the same, but only on some machines in our org.Teleplay
@DanielWilliams I see. It would depend on the Mac OS version? I'm using 13.5.2 (22G91)Brawny
No luck on Xcode 15.2.0 yetBrawny
It seems it does not reproduce in Xcode 15.3. How about you guys?Brawny
By the way, I upgraded macOS to 14.4 lately. So, it could also be the reason thoughBrawny
B
1

For the record. This problem stopped reproducing with Xcode 15.3 and no longer occurs with later versions of Xcode, so it was most likely a bug in older Xcode.

Brawny answered 5/9 at 5:3 Comment(0)
L
1

I think the problem is that your Terminal is running in Rosetta (i386) mode.

You can test this out by running

> arch

which will probably return

i386

To switch architectures:

> arch -arm64 /bin/zsh 

then

> arch

should show

arm64

Then your xcodebuild should work as expected

You can also check the info on your Terminal app and it'll probably be set to "Open using Rosetta":

enter image description here

Laryngoscope answered 21/3 at 22:1 Comment(1)
Thank you for your answer. When I saw it for the first time, I was sure that was the case. But I can't confirm now it was it since the issue seems to be gone with the Xcode 15.3 (or macOS version issue) even with the i386 arch. So, if people still use the Xcode 15.2 or prior, I'm glad if you could verify the Ashley's answer so that I can accept this as an correct answer.Brawny
B
1

For the record. This problem stopped reproducing with Xcode 15.3 and no longer occurs with later versions of Xcode, so it was most likely a bug in older Xcode.

Brawny answered 5/9 at 5:3 Comment(0)
K
-1

Not really a full solution, but this command allowed me to get past the same issue:

defaults write com.apple.dt.Xcode IDESkipMacroFingerprintValidation -bool YES
Knipe answered 14/11, 2023 at 21:52 Comment(1)
Sorry for the late reply. I tried your solution but it didn't work for me. I also tried -skipMacroValidation option but no luck.Brawny

© 2022 - 2024 — McMap. All rights reserved.