27

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
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
    – Masroor
    Commented Apr 10, 2023 at 7:35
  • 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 stackoverflow.com/a/75921492/5461816
    – Masroor
    Commented Apr 10, 2023 at 7:38
  • i have tried so many solutions none worked\ Commented Oct 30, 2023 at 11:22

16 Answers 16

62

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

11
  • 2
    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. 😢 Commented Apr 10, 2023 at 8:09
  • I attached an image to answer, clean and archive again. Commented Apr 10, 2023 at 8:18
  • @TaimoorSikander github.com/CocoaPods/CocoaPods/issues/11808 Commented Apr 10, 2023 at 8:31
  • Bro I'm really thank fun but still same issue. Even Achieve is disabled. Commented Apr 10, 2023 at 8:48
  • 1
    This worked for me. Running pod update reverted it back to the bad way so watch out if you update your pods.
    – Micro
    Commented Jul 27, 2023 at 5:21
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
3
  • Did your issue solve? Commented Apr 12, 2023 at 14:31
  • 2
    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
    – rashidotm
    Commented Apr 16, 2023 at 18:58
  • It was the "Generated" setting on each Configuration that was missing for me
    – James
    Commented Oct 18, 2023 at 9:00
11

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

  • set -e
  • set +e
3
  • Thanks.it worked. none of the solution works except this. i was using XCode 14.2 and React-Native 0.64.2 Commented Oct 2, 2023 at 7:48
  • This worked for me, but editing node_modules feels dangerous. Should I patch the package or is there another way?
    – JCraine
    Commented Nov 17, 2023 at 8:28
  • Update: dev is fine but when trying to archive the build, it fails.
    – JCraine
    Commented Nov 23, 2023 at 2:17
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.

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 =) Commented Feb 13 at 12:50
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

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

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

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
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.

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.

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

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

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.
0

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!

0

for react native .74 (M3)

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

For M1:

npx react-native-clean-project

cd ios && pod deintegrate && pod install

1
  • Please, edit and try for How to Answer, describe the effect of what you propose and explain why it helps to solve the problem, make the additional insight more obvious which you contribute beyond existing answers, the relevant advantage which your solution achieves, especially if the difference is so small and non-obvious. Find help with formatting your post here: stackoverflow.com/help/formatting .
    – Yunnosch
    Commented Jul 5 at 16:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.