37

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
4
  • 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 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 Commented Apr 10, 2023 at 7:38
  • i have tried so many solutions none worked\ Commented Oct 30, 2023 at 11:22
  • See the solution into Comments Its worked for me: fluttertpoints.com/flutter-interview-questions#comment-745 Commented Aug 12 at 11:52

19 Answers 19

65

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

Sign up to request clarification or add additional context in comments.

11 Comments

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. 😢
I attached an image to answer, clean and archive again.
Bro I'm really thank fun but still same issue. Even Achieve is disabled.
This worked for me. Running pod update reverted it back to the bad way so watch out if you update your pods.
|
32

Followed @Maziar Saadatfar's 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

4 Comments

Did your issue solve?
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
It was the "Generated" setting on each Configuration that was missing for me
I signed in to thank you! Option 2 worked. Setting #1 was already in place for me so I did not have to make that change.
13

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

  • set -e
  • set +e

5 Comments

Thanks.it worked. none of the solution works except this. i was using XCode 14.2 and React-Native 0.64.2
This worked for me, but editing node_modules feels dangerous. Should I patch the package or is there another way?
Update: dev is fine but when trying to archive the build, it fails.
Underrated answer. In my case, I already had source="$(readlink -f "${source}")" so the other answers were unhelpful, but this is what I needed.
For FlutterFire issue see the comments: fluttertpoints.com/flutter-interview-questions#comment-745
6

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 Comment

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 =)
1

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.

Comments

1

For M1:

npx react-native-clean-project

cd ios && pod deintegrate && pod install

1 Comment

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

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

Comments

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

Comments

0

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

Comments

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.

Comments

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

Comments

0

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

Comments

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

Comments

0

In my case -f was already within the code source="$(readlink -f "${source}")" so I went to target build settings -> search for 'User script sandbox' -> set to No

Comments

0

Using expo with :

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

Comments

0
  1. Delete ios/.xcode.env.local
  2. Setting .xcode.env export NODE_BINARY=$(command -v node)
  3. Xcode use Rosetta run

Comments

0

For .74 (M3):

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

Comments

0

I faced the same issue and managed to solve it. In my case, the problem was caused by an incorrect Node binary path stored in the .xcode.env.local file.

Inside my project:

Project/ios/.xcode.env.local

The file contained:

export NODE_BINARY=/opt/homebrew/Cellar/node/23.5.0/bin/node

This path was wrong. I fixed it by updating it to:

export NODE_BINARY=/opt/homebrew/bin/node

After updating, I:

  1. Cleared the DerivedData for the project.

  2. Cleaned the project in Xcode.

  3. Rebuilt and ran it again.

That solved the issue for me.

Machine details:

  • MacBook Air M2

  • React Native: 0.78.0

Comments

-1

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.

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.