How to fix Command PhaseScriptExecution failed with a nonzero exit code on flutter run in macOS?

Solution 1:

You won't believe it, but in my case the problem was caused by a corrupted image that was used to generate the launcher icons. Something with the alpha channel was messed up. After I fixed it, the product could be archived successfully.

Solution 2:

Simple Commands that made my archive successful after 2 days of struggle:

flutter clean
flutter pub get
flutter pub upgrade
cd iOS
pod install
pod update 

And the issue is resolved.