Failed to launch macOS app built in Xcode

12,428

I don't know how you are building your app, but if LSOpenURLsWithRole is returning permError = -54, this means you have a permission error on opening a file. This can mean a lot of things, but building an app in release mode is no longer what Apple recommends for you to do. Apple prefers that you use Archive and then you export the app in Organizer to be used by your users. By using this work flow, normally you can do everything using the Xcode defaults for building an app. If you don't, then you need to be more careful with the settings you choose for building in release mode.

For a quick and dirty approach, I would try the following:

1) Open the terminal

2) Type: chmod +x "/Applications/Gaetano Lunches.app/Contents/MacOS/Gaetano Lunches"

3) Try to launch your app and see if it helps. If it helps, there is something messed up with your build settings, which is failing to change the file permissions somewhere for your executable to have the right permissions to be launched.

Another thing you could try is see whether your app was blacklisted by Gatekeeper, because somehow it determined your app is doing suspicious things on your own system. If that is the case, then you can try this to see what gatekeeper is assessing:

spctl -a "/Applications/Gaetano Lunches.app"

If for some weird reason you app is being blacklisted by Gatekeeper, you can always add your app manually and whitelist it for Gatekeeper:

spctl --add "/Applications/Gaetano Lunches.app"

If all fails, you can try to reset the whole database, but you will need super user access:

sudo spctl --reset-default

However, I think these are just quick fixes, and if you keep needing this is because your build settings in Xcode must be adjusted. More on that, if any of these solutions work. Let me know about that.

Share:
12,428
Denis Óbukhov
Author by

Denis Óbukhov

Updated on June 05, 2022

Comments

  • Denis Óbukhov
    Denis Óbukhov almost 2 years

    I've built an App in Xcode in release mode. Is signed with valid Developer ID certificate. And the app launches fine on some MacBooks. But on another launch fails with error

    The application %name% can't be opened.

    Then I try to launch it from terminal with open command it says

    LSOpenURLsWithRole() failed with error -54 for the file /Applications/Gaetano Lunches.app.

    And then I try to launch directly the binary file from package contents it says

    -bash: /Applications/Gaetano Lunches.app/Contents/MacOS/Gaetano Lunches: Operation not permitted

    On all MacBooks app installation from Anywhere is allowed. spctl-master is disabled. Permissions for files are correct. But the app cannot be launched.

  • Denis Óbukhov
    Denis Óbukhov almost 5 years
    Ok. Thank you for respond. I've tried to rebuild the app with Archive function, and I notarized the app, but it has no effect. As I mentioned in my question spctl is disabled on all machines where the app can't be launched.
  • Denis Óbukhov
    Denis Óbukhov almost 5 years
    I've checked the system.log file for the machine where the app can't be launched and it show following text > Jul 12 15:34:18 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.oneshot.0x10000aa1.Gaetano Lunches[55855]): Service could not initialize: 18E226: xpcproxy + 11291 [1534][1571C9B2-C489-3268-9D6B-73137AC77303]: 0x1 > Jul 12 15:34:18 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.oneshot.0x10000aa1.Gaetano Lunches[55855]): Service exited with abnormal code: 78
  • jvarela
    jvarela almost 5 years
    Is also launchctl disabled? Is your app sandboxed or are you trying to write or open a file where your app is not allowed to?
  • Denis Óbukhov
    Denis Óbukhov almost 5 years
    My APP use URLsession to get JSON data from remote URL. App sandbox is enabled with a tick on "Outgoing connections"
  • jvarela
    jvarela almost 5 years
    Because the error -54 and now the error 78 in launchd all point out to a permissions error. It seems as though you are trying to read from or write to a directory your app does not have permissions to. Where are you writing what you are downloading?
  • Denis Óbukhov
    Denis Óbukhov almost 5 years
    I do not read any files from filesystem in my App. There is an image in one window, but it uses source from app's assets directory. And I'm downloading json from remote source. You can find source code here github.com/obukhow/OggettoLunchMac/blob/…
  • jvarela
    jvarela almost 5 years
    Yes, but you are writing to the user preferences. That might not be allowed in your managed environment. Can you comment out the code in lines 21 and 22 where you write to the user preferences after downloading your payload? Check if that solves the problem, If it does, you need to store that data somewhere else where you have permissions to write.
  • Denis Óbukhov
    Denis Óbukhov almost 5 years
    I've removed all UserDefaults.standard calls, rebuilt the app. But it still can't be opened. In system.log I can see the same error Jul 15 09:59:40 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.oneshot.0x10000ad8.Oggetto Business Lunches[59755]): Service could not initialize: 18E226: xpcproxy + 11291 [1534][1571C9B2-C489-3268-9D6B-73137AC77303]: 0x1 Jul 15 09:59:40 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.oneshot.0x10000ad8.Oggetto Business Lunches[59755]): Service exited with abnormal code: 78
  • jvarela
    jvarela almost 5 years
    Can you use launchctl to extend what you’re seeing or is that also disabled?