Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to launch macOS app built in Xcode

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.

like image 681
Denis Óbukhov Avatar asked Jul 09 '19 10:07

Denis Óbukhov


1 Answers

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.

like image 133
jvarela Avatar answered Sep 19 '22 10:09

jvarela