Taimoor Sikander
Taimoor Sikander

Reputation: 1033

Xcode Error PhaseScriptExecution failed with a nonzero exit code

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

Upvotes: 31

Views: 108670

Answers (17)

In my case, the Pods-[your-project-name]-frameworks.sh file in my project has already this line source="$(readlink -f "${source}")" instead of source="$(readlink "${source}")". And because I have configured flavor of build in my project, I assume that it might has something wrong in the pod reference for each flavor. Jackpot!! I did the wrong pod configuration for the flavors. If you are in my case, take a look on your pod config if it is correct.

Go to Runner under Project -> Info -> Configuration and check yours. Hope this help someone.

enter image description here

Upvotes: 0

Wajid Ali
Wajid Ali

Reputation: 91

For M1:

npx react-native-clean-project

cd ios && pod deintegrate && pod install

Upvotes: 1

Imtee
Imtee

Reputation: 1393

for react native .74 (M3)

npx react-native-clean-project
cd ios && pod deintegrate
npx pod-install
npx react-native start --reset-cache

Upvotes: 0

Pavel L
Pavel L

Reputation: 111

I faced a similar issue and was able to resolve it by ensuring that the script file had the correct permissions to be executed. You can use the chmod command to set the executable permissions if needed. Navigate to the directory containing the script file (ios/Pods/Target Support Files/Pods-Runner) and run the following command:

chmod +x Pods-Runner-frameworks.sh

I hope this helps!

Upvotes: 0

jamm55
jamm55

Reputation: 41

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.

Upvotes: 0

tread khuram
tread khuram

Reputation: 314

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

Upvotes: 0

Ddong
Ddong

Reputation: 1

  1. delete ios/.xcode.env.local
  2. setting .xcode.env export NODE_BINARY=$(command -v node)
  3. xcode use Rosetta run
  4. success

Upvotes: 0

OneXer
OneXer

Reputation: 355

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.

Upvotes: 1

Bohdan
Bohdan

Reputation: 1

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.

Upvotes: 0

nochkin
nochkin

Reputation: 710

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

Upvotes: 0

Kingsley Akpan
Kingsley Akpan

Reputation: 273

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

Upvotes: 0

Md Rashed Nizam
Md Rashed Nizam

Reputation: 312

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}")"

Upvotes: 1

kdc
kdc

Reputation: 41

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.

Upvotes: 4

klamm
klamm

Reputation: 161

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

  • set -e
  • set +e

Upvotes: 12

Namatullah Wahidi
Namatullah Wahidi

Reputation: 17

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

Upvotes: 0

Taimoor Sikander
Taimoor Sikander

Reputation: 1033

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

Upvotes: 31

Maziar Saadatfar
Maziar Saadatfar

Reputation: 1895

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

Upvotes: 64

Related Questions