Xcode 15 UIKit Preview FailedToLaunchAppError: Failed to launch error

1k views Asked by At

I'm trying to preview UIKit view using #Preview macro in Xcode 15, but got this error

== PREVIEW UPDATE ERROR:

    FailedToLaunchAppError: Failed to launch
    
    ==================================
    
    |  RemoteHumanReadableError: The operation couldn’t be completed. Transaction failed. Process failed to launch. (process launch failed)
    |  
    |  BSTransactionError (1):
    |  ==error-reason: process launch failed
    |  ==transaction: <FBApplicationProcessLaunchTransaction: 0x600003b287e0>
    |  ==precipitating-error: Error Domain=FBProcessExit Code=64 "The process failed to launch." UserInfo={NSLocalizedFailureReason=The process failed to launch., BSErrorCodeDescription=launch-failed, NSUnderlyingError=0x600000c1ad90 {Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x600000c1aee0 {Error Domain=NSPOSIXErrorDomain Code=111 "Unknown error: 111" UserInfo={NSLocalizedDescription=Launchd job spawn failed}}}}}
    |  ==error-description: Process failed to launch.
    |  ==NSLocalizedFailureReason: Transaction failed. Process failed to launch. (process launch failed)

Code I'm trying to preview on iPhone 15

import UIKit

final class SomeViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .red
    }
}

@available(iOS 17, *)
#Preview {
    SomeViewController()
}
1

There are 1 answers

1
XavierZzz On BEST ANSWER

Our project could not initially be debugged using the simulator in Apple silicon, so it could not be previewed.

After the arm64 architecture is excluded from each target: enter image description here the simulator works, but #Preview still doesn't work and gives the same error message as your question: failed to launch(I'm pretty sure we got exactly the same error).

After trying various methods:

  • deleting all the code in didFinishLaunch
  • deleting the Preview cache
  • deleting the Simulator cache
  • deleting DerivedData
  • restarting Xcode
  • restarting Mac

all failed,Until we remembered how to build an App using Rosetta simulator: enter image description here

Use the Rosetta simulator as the build target and set the preview to be the same device,A miracle happened: enter image description here

It is important for us to: We turned off auto-refresh canvas to make Preview finally work. enter image description here