Xcode Error PhaseScriptExecution failed with a nonzero exit code
Asked Answered
C

13

23

I've created flutter app and now want to create archive for distribution in Xcode 14.3.

Issue

  1. Archive is disabled.
  2. Getting this error with build failed PhaseScriptExecution failed with a nonzero exit code

Already tried

  1. Pod Install
  2. Clean build folder
  3. Open the Xcode project folder in your Terminal app. Enter and execute the following command: pod deintegrate Execute this command: pod install Re-open Xcode > go to Product > Clean Build Folder. Run your app again.

NOTE Head over to Keychain Access.Select Lock & unlock again from the login option is disabled. How to enable it?

Looking forward for your help.

SCREENSHOT enter image description here

Podfile

# Uncomment this line to define a global platform for your project
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end
Cooee answered 10/4, 2023 at 7:16 Comment(3)
Can you please provide a screenshot of the error? This error is not enough the explain the reason. Also, please provide your Xcode version as well – Urbas
If you are using Xcode 14.3 then this is your solution. Because of the latest cocoapods changes archive is failing for all of the existing projects https://mcmap.net/q/89125/-xcode-14-command-phasescriptexecution-failed-with-a-nonzero-exit-code – Urbas
i have tried so many solutions none worked\ – Abuttals
B
60

you should search this file in your project:

Pods-[your-project-name]-frameworks.sh (...-frameworks.sh)

and edit this section:

 if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink "${source}")"
  fi

to

 if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink -f "${source}")"
  fi

source="$(readlink "${source}")" -----> source="$(readlink -f "${source}")"

Workaround is to update all the generated ...-frameworks.sh files to add the -f flag to the call to readlink. In other words, replace source="$(readlink "${source}")" with source="$(readlink -f "${source}")"

enter image description here

this link maybe help you: https://github.com/CocoaPods/CocoaPods/issues/11808

Burette answered 10/4, 2023 at 7:54 Comment(11)
Hi, I tried this in framework.sh class. Is there is only one place where I have to change this? As I've tried and changed readlink only at one place but didn't work for me. 😒 – Cooee
I attached an image to answer, clean and archive again. – Burette
@TaimoorSikander github.com/CocoaPods/CocoaPods/issues/11808 – Burette
Bro I'm really thank fun but still same issue. Even Achieve is disabled. – Cooee
@TaimoorSikander could you please attach an image? – Burette
Also in the Log I found this.. /bin/sh: /packages/flutter_tools/bin/xcode_backend.sh: No such file or directory – Cooee
can you share your podfile? and update your cocoapods "sudo gem install cocoapods" – Burette
Attached pod file – Cooee
Hi, I have added as you said -f but there was 1 more thing that I had to do. – Cooee
the issue is for cocoapods until update, but the solution is "-f" – Burette
This worked for me. Running pod update reverted it back to the bad way so watch out if you update your pods. – Riplex
C
30

As suggested by

@Maziar Saadatfar

Followed his instructions as stated in step 1 below and after this, one more thing that I have to do as stated in step 2.

  1. You should search this file in your project:

Pods-[your-project-name]-frameworks.sh (...-frameworks.sh)

and edit this section:

if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink "${source}")"
  fi

to

if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink -f "${source}")"
  fi

source="$(readlink "${source}")" -----> source="$(readlink -f "${source}")"

Workaround is to update all the generated ...-frameworks.sh files to add the -f flag to the call to readlink. In other words, replace source="$(readlink "${source}")" with source="$(readlink -f "${source}")"

  1. Open Xcode - Click on Runner(Top one) Select the Runner from "PROJECT" Not from "TARGETS" Select configuration And update all the modes as this photo enter image description here
Cooee answered 10/4, 2023 at 10:15 Comment(4)
Did your issue solve? – Burette
I just moved to M1 chip and this did not work for me. using Xcode 14.3 & Flutter 3.7.11 & Cocoapods 1.12.0 – Mixture
You just saved my week!!...thank you! – Melisamelisande
It was the "Generated" setting on each Configuration that was missing for me – Amenity
A
11

This worked for me: updating node_modules/react-native/scripts/find-node.sh @ L7

  • set -e
  • set +e
Agnew answered 21/9, 2023 at 20:47 Comment(3)
Thanks.it worked. none of the solution works except this. i was using XCode 14.2 and React-Native 0.64.2 – Brushwork
This worked for me, but editing node_modules feels dangerous. Should I patch the package or is there another way? – Indra
Update: dev is fine but when trying to archive the build, it fails. – Indra
C
2

In my case, the .xcode.env.local file under ios/ was pointing to the wrong (outdated) node installation.

export NODE_BINARY="/opt/homebrew/Cellar/node@18/18.13.0_1/bin/node"

Updated this to the current node path and no more PhaseScriptExecution error.

Caftan answered 27/10, 2023 at 3:51 Comment(1)
This is a somewhat unique scenario to change your node binary mid-project, but it was also the issue I faced, so thank you for this answer =) – Broadcloth
E
0

Add -f within this code source="$(readlink -f "${source}")"

file location ios/Pods/Target Support Files/Pods-Runner

You can add -f to your project file like this

Ehtelehud answered 12/8, 2023 at 6:59 Comment(0)
U
0

You will get "Pods-[your-project-name]-frameworks.sh" this file inside "ios/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh" file.

then open the file and update below line :

source="$(readlink "${source}")"

to

source="$(readlink -f "${source}")"
Ulric answered 6/11, 2023 at 13:44 Comment(0)
C
0

Make sure that your project path doesn't have a space in between the names. That was the cause of my issue.

Cumae answered 28/11, 2023 at 19:38 Comment(0)
C
0

I had the same issue recently. The problem was in node_modules/react-native/scripts/react-native-xcode.sh script.

The problem comes from ipconfig getifaddr which may fail if I don't have an IP assigned to one of the interfaces.

I had to replace

set -x -e

With

set -x
Carden answered 7/12, 2023 at 4:39 Comment(0)
R
0

I opened the logs in XCode and saw that my error falls in "Bundle React Native code and images" and in the recommendations it was written that two libraries should be install "Please install [email protected], @expo/metro-runtime@~3.1.1". I installed the libraries using the command "npx expo install react-dom @expo/metro-runtime" and that helped me.

Roomer answered 30/1 at 15:7 Comment(0)
B
0

Check the folder in which the application code is stored. If there any whitespaces in the folder name, it will also generate this error. I had mine in a folder called "XCode Projects". After I renamed to "XCodeProjects", I restarted Xcode and rebuilt successfully. Error message is very inadequate with no detail on how to address it.

Bresnahan answered 16/2 at 17:14 Comment(0)
V
0
  1. delete ios/.xcode.env.local
  2. setting .xcode.env export NODE_BINARY=$(command -v node)
  3. xcode use Rosetta run
  4. success
Verdha answered 1/3 at 7:9 Comment(0)
M
0

Last but not least, The solution that worked for me was to delete ".xcode.env.local" and start the whole process again

Manhole answered 5/3 at 7:19 Comment(0)
U
0

using expo with react-native

  • If you are using expo react-native to build an ios of the app. Try deleting the /ios folder and then use eas build --platform ios. It would automatically create a new prebuild. That stopped the errors for me. You need an apple developer account though.
Ungotten answered 18/3 at 10:44 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.