Failed to launch macOS app built in Xcode
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.
Denis Óbukhov
Updated on June 05, 2022Comments
-
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 saysLSOpenURLsWithRole() 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 almost 5 yearsOk. 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 almost 5 yearsI'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 almost 5 yearsIs 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 almost 5 yearsMy APP use URLsession to get JSON data from remote URL. App sandbox is enabled with a tick on "Outgoing connections"
-
jvarela almost 5 yearsBecause 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 almost 5 yearsI 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 almost 5 yearsYes, 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 almost 5 yearsI'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 almost 5 yearsCan you use launchctl to extend what you’re seeing or is that also disabled?