63

I am trying to add flutter to the existing app. So before doing on the production app I tried with brand new Xcode 10 Single View Application. I followed the tutorial here on https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps and got stuck after adding the run script in the build phase of my target. It's giving the error:

Error:

iphoneos/AFEiOS.build
    export TEMP_ROOT=/Users/dhavalkansara/Library/Developer/Xcode/DerivedData/AFEiOS-gctxucyuhlhesnfkbuxfswkozboo/Build/Intermediates.noindex
    export TOOLCHAINS=com.apple.dt.toolchain.XcodeDefault
    export TOOLCHAIN_DIR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
    export TREAT_MISSING_BASELINES_AS_TEST_FAILURES=NO
    export TeamIdentifierPrefix=RQ9BPQCP49.
    export UID=501
    export UNLOCALIZED_RESOURCES_FOLDER_PATH=AFEiOS.app
    export UNSTRIPPED_PRODUCT=NO
    export USER=dhavalkansara
    export USER_APPS_DIR=/Users/dhavalkansara/Applications
    export USER_LIBRARY_DIR=/Users/dhavalkansara/Library
    export USE_DYNAMIC_NO_PIC=YES
    export USE_HEADERMAP=YES
    export USE_HEADER_SYMLINKS=NO
    export VALIDATE_PRODUCT=NO
    export VALID_ARCHS="arm64 arm64e armv7 armv7s"
    export VERBOSE_PBXCP=NO
    export VERSIONPLIST_PATH=AFEiOS.app/version.plist
    export VERSION_INFO_BUILDER=dhavalkansara
    export VERSION_INFO_FILE=AFEiOS_vers.c
    export VERSION_INFO_STRING=""@(#)PROGRAM:AFEiOS  PROJECT:AFEiOS-""
    export WRAPPER_EXTENSION=app
    export WRAPPER_NAME=AFEiOS.app
    export WRAPPER_SUFFIX=.app
    export WRAP_ASSET_PACKS_IN_SEPARATE_DIRECTORIES=NO
    export XCODE_APP_SUPPORT_DIR=/Applications/Xcode.app/Contents/Developer/Library/Xcode
    export XCODE_PRODUCT_BUILD_VERSION=10E1001
    export XCODE_VERSION_ACTUAL=1020
    export XCODE_VERSION_MAJOR=1000
    export XCODE_VERSION_MINOR=1020
    export XPCSERVICES_FOLDER_PATH=AFEiOS.app/XPCServices
    export YACC=yacc
    export arch=undefined_arch
    export variant=normal
    /bin/sh -c /Users/dhavalkansara/Library/Developer/Xcode/DerivedData/AFEiOS-gctxucyuhlhesnfkbuxfswkozboo/Build/Intermediates.noindex/AFEiOS.build/Debug-iphoneos/AFEiOS.build/Script-19DAA30A22C0FB0100A039E2.sh

The path lib/main.dart does not exist
The path  does not exist
Command PhaseScriptExecution failed with a nonzero exit code

I have tried below things.

My pod file:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'

target 'AFEiOS' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for AFEiOS

  target 'AFEiOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'AFEiOSUITests' do
    inherit! :search_paths
    # Pods for testing
  end

    flutter_application_path = '/Users/dhavalkansara/FlutterToNative/AFE_flutter/'
    eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)


end
  • Already added FLUTTER_ROOT in my project.

Please help me out with this issue.

Dhaval Kansara
  • 3,478
  • 5
  • 22
  • 50

32 Answers32

75

This work for me Thanks Alexander Lozano, I upload image for Xcode Version 12.0.1

Xcode Version 12.0.1

Diego Sanchez
  • 1,369
  • 1
  • 11
  • 5
  • 1
    I GOT NEW ERROR: Undefined symbols for architecture armv7: "_OBJC_CLASS_$_FlutterAppDelegate", referenced from: type metadata for Runner.AppDelegate in AppDelegate.o "_OBJC_METACLASS_$_FlutterAppDelegate", referenced from: _OBJC_METACLASS_$__TtC6Runner11AppDelegate in AppDelegate.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation) Undefined symbols for architecture arm64: "_OBJC_CLASS_$_FlutterAppDelegate", referenced from: – vin shaba Dec 15 '21 at 14:18
  • This helped me on my Mac with M1 chip, my friend didnt need this on Intel chip on the same project. Can this change be dangerous? – stackich Apr 11 '22 at 16:41
  • 2
    I have 1 error message, I check the box, now I have 3 errors. Thanks – msalihbindak Jun 02 '22 at 09:58
  • 18
    People stop doing this. I see this is an accepted answer. but please turn it back off. Check the Comment by jmagman on flutter. https://github.com/flutter/flutter/issues/99387#issuecomment-1105467295. this is a terrible advice and don't follow it. Changing this setting will cause the issue Flutter.h not found. – Akash g krishnan Jun 21 '22 at 13:37
  • @Akashgkrishnan In my case this solution works. If this is not an option, which one is the solution? – Fabio Sep 02 '22 at 20:47
  • @Fabio in most cases the issue is due to switching branches while app is running and the app being too much dependant on old Plugins. Creating a new iOS Folder in most cases fixes the issue. also please read the GitHub Comment posted. where even the flutter team says that disabling run scripts should never be done. – Akash g krishnan Sep 23 '22 at 12:55
  • 3
    This is a bad solution that can lead to other problems. For me updating flutter has worked multiple times when I've had this error - ```flutter upgrade``` – MrHarvey Oct 22 '22 at 23:15
  • My issue and solution was different. https://stackoverflow.com/a/75666151/9255257 – Vipin Krishna Mar 07 '23 at 19:07
  • I tried this solution, rebuilt the pod file, updated flutter and upgraded but none of them solved my problem. Please help me – Muhammed Yusuf Taşkesenligil Jul 17 '23 at 19:15
31

this works for me: xcode 11.3.1

xcode ->targets->runner

in build phases: run script and thin binary, select: run script only when installing

TuGordoBello
  • 4,350
  • 9
  • 52
  • 78
ALEXANDER LOZANO
  • 1,874
  • 3
  • 22
  • 31
6

I was having the issue for 2 days.

My failure was slightly different:

Failed to package /path/to/my/app.
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in parallel

I was on Flutter 2.5.1, I tried all of the suggestions found here (amongst others I googled). I wish I knew the answer or understood why, but a simple

`flutter upgrade` 

Worked for me (I ended up with 2.5.3)

Jared Anderton
  • 826
  • 9
  • 12
4

Anyone facing problem when building or archiving for 1st time on xcode

How I resolved this issue:

  1. clean flutter project with flutter clean
  2. build project with flutter build ios. This will sign app to the appstore
  3. build/archive app on xcode
Paras Rai
  • 122
  • 1
  • 6
3

This worked for me:
1) Add this to your podfile:

flutter_application_path = '/Users/dhavalkansara/FlutterToNative/AFE_flutter/'
    eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)

    install_all_flutter_pods(flutter_application_path)

PS. You may also need to do that for each target, i.e

target 'AFEiOSTests' do
    inherit! :search_paths
    install_all_flutter_pods(flutter_application_path)
    # Pods for testing
  end

  target 'AFEiOSUITests' do
    inherit! :search_paths
    install_all_flutter_pods(flutter_application_path)
    # Pods for testing
  end

2) Run pod install

Viktor Varsano
  • 110
  • 1
  • 1
  • 10
2

By doing flutter clean. Xcode builds clean.(Key: command+shift+k).

xcode ->targets->runner

in build phases: run script and thin binary, unselect: run script only when installing

then run flutter run in the terminal of the project resolve the issue for me.

Shahryar Rafique
  • 1,211
  • 15
  • 35
  • I use Xcode 12.5.1, Flutter 2. This solution works for me. Thanks a lot – samthui7 Sep 05 '21 at 09:10
  • do NOT do this, per https://github.com/flutter/flutter/issues/99387#issuecomment-1081238267, since "you're shutting off all the Flutter tooling that builds your dart app." – qix Aug 06 '22 at 08:52
2

If you dig deep and try and find out what is causing this error - it will help you to go to the right direction. For me the reason for this error was "

"/packages/flutter_tools/bin/xcode_backend.sh: No such file or directory"

Now in order to find xcode_backend.sh the FLUTTER_ROOT variable needs to be defined. It is defined in a file called Flutter/Generated.xcconfig, which is generated when you run flutter pub get or flutter build.

Goto Project -> Runner -> Info -> Configurations

Debug Runner -> Generated (under Runner) Runner -> Pods-Runner.debug

Release Runner -> Generated (under Runner) Runner -> Pods-Runner.release

Profile Runner -> Generated (under Runner) Runner -> Pods-Runner.profile

At the end all the 3 will have 2 configurations set.

Best of luck :)

1

Fix for me was force quitting Xcode. There recently was update, after which this issue appeared. After normal quitting and opening, there was error visible. But after force quitting and opening, Xcode showed dialog box, that some of its dependencies are missing and they will be downloaded. After that build was working for me again.

Andris
  • 3,895
  • 2
  • 24
  • 27
1

Somewhat related to other questions, such as this. For me this started happening after some update in my Mac. The solution included a flutter clean + flutter pub get and restarting both the device (iPhone) and computer (Mac) - restarting the Mac made all the difference. Other answers may suggest to mark the "For install builds only" option on Xcode - that actually broke things for me, build started complaining about not finding Flutter.h. So yeah, restarting things may solve your problem. Perhaps throw in a flutter upgrade as well.

nelsonspbr
  • 162
  • 8
1

Easy way to fix this:

  1. Go to Menu -> System Preferences -> Security & Privacy.
  2. Choose the Privacy Tab.
  3. Select the Full Disk Access item in the left list.
  4. Select Xcode in the right list.

Source: https://github.com/flutter/flutter/issues/76302

Sahil Sonawane
  • 1,144
  • 9
  • 18
1

this happen because some packages not updated

in Ios folder

  1. delete pods folder
  2. delete podfile.lock
  3. in podfile change version ( platform :ios, '11.0') '11' or higher
  4. flutter pub upgrade --major-versions (in project terminal)
  5. pod install (in ios terminal)
  6. flutter run
1

I tried everything from flutter clean to pod deintegrate to restarting to changing to "for install builds only". None solved my problem. This happened every time I made large changes to an auto-generated API. Deleting the pushing everything, deleting the folder, and re-cloning worked for me, but it was of course none ideal.

Instead of taking a solution wholesale here, you should run flutter run --verbose and trace the source of the error. In my case, I traced Member not found: 'FirebaseAppPlatform.verifyExtends'. to which this solution worked.

With a widely attributable error like this, always assess the risks of even more widely attributable solutions. Some of the solutions are quite dangerous.

Kevin Loo
  • 31
  • 4
  • 1
    `flutter run --flavor dev --verbose` does indeed help greatly in identifying the specific error likely related to the cause of the nonzero-exit error. – Emile Nov 09 '22 at 15:49
1

for flutter developers, I am also facing this problem and after doing RnD i am able to solve it as follow:

find frameworks.sh files to add the -f flag to the call to readlink.

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

replace with

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

here is the directory to find it:

Pods --> Target support files --> Pods-(Project_Name) --> frameworks.sh(Pods-Runner-frameworks)

Remember(if you are using notification services like oneSignal etc. make sure to check bundle version before archiving )

Arslan
  • 194
  • 1
  • 10
0

For beginners: (tested on XCODE 12.0.1) open Xcode--> Open a project or file --> go to the flutter app path/ios directory--> open --> Runner and follow attached image steps enter image description here

Mohsin AR
  • 2,998
  • 2
  • 24
  • 36
  • 5
    As per this comment on GitHub: https://github.com/flutter/flutter/issues/99387#issuecomment-1081238267 this is a terrible advice and it will generate a new error `Flutter/Flutter.h not found` – t3nsa Aug 14 '22 at 02:52
  • @t3nsa you are absolutely correct. – Nifal Nizar Oct 22 '22 at 02:17
0

How I resolved this issue:

step 1: open up your flutter iOS directory in Xcode and try to build, it should give a more detailed overview of where the error is in your code.

PhaseScriptExecution failed with a nonzero exit code an error returned by Xcode build engine - you probably ignored warnings not obvious syntax error in your flutter code, could be a scope or imports declaration.

Ensure your build succeeds in Xcode before closing simulator.

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

Try to run sudo rm -rf /private/var/folders/* in Terminal. This resolves my problem.

Refer to: https://apple.stackexchange.com/a/176374/448505

Yanni
  • 580
  • 2
  • 6
  • 21
0

This worked out strange for me.

There recently was an new update, after which this issue appeared. After normal quitting and opening, error was visible.

Force quit the xcode and rebuilding the app worked for me.

Vicky Salunkhe
  • 9,869
  • 6
  • 42
  • 59
0

Building it from the CLI fixed it for me

flutter build ipa

Alberto M
  • 1,608
  • 1
  • 18
  • 42
0

I trying many things for me apps works after update flutter with flutter upgrade I hope works for you all also by the way ı update may mac and xcode also :)

0

TL;DR Try updating Flutter -> flutter upgrade

I had this error a few times and always try the flutter clean, flutter pub get...etc but it doesn't work for me. I also try restarting laptop, deleting recently added assets (as some comments suggest) but none of it works.

Then I remember how I fixed it last time by updating Flutter, and it has just worked for me again so definitely worth a try

MrHarvey
  • 192
  • 2
  • 2
  • 16
0

Make sure configuration is set correctly to Debug, mine was set to "none"

enter image description here

Niels
  • 1,366
  • 15
  • 21
0

sometimes it can be happen due to one of your outdated library that being used. try following command.

flutter pub upgrade --major-versions

after that run flutter pub get

aligur
  • 3,387
  • 3
  • 34
  • 51
0

This worked for me to generate an IPA file for deployment:

flutter build ipa --export-method development --no-tree-shake-icons
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
0

For Mac M1 developers

Follow the steps

1- Go to the iOS folder and delete the podfile.lock,pods

2- arch -x86_64 pod install may have to be used instead of pod install

0

I got this error after i update xcode. All that i did to resolve it was to upgrade flutter.

M.Gafaru
  • 1
  • 1
  • 3
0

I tried everything and spent 3 to 4 days.

I found the solution with the below steps.

  1. Remove the iOS Folder of your Flutter project.

  2. Re-Create iOS Folder using the below command.

    flutter create -i swift .

  3. Go to iOS the iOS Folder and install pod.

    pod install

  4. Run the project. flutter run

Note: I know these steps are not always solved but it works for me.

I created this project with Flutter 2.2.3 (Dart 2.13.4) 2 or 3 years ago and never try to run it on iOS, Now Flutter running on 3.10.6 (Dart 3.0.6), and maybe some iOS project folder create with the old Drat Framework.

My system Dart Framework is always updated and tries to run with the old Dart compile version.

I think this one is in my case.

Vivek
  • 4,916
  • 35
  • 40
0

With my case, I try many another way not working. But final follow step below to fix:

  • Flutter clean
  • Flutter Pub get
  • cd ios & pod install

And last and most important, restart your MacBook because most of the time Xcode needs restart to adopt new changes.

Doan Bui
  • 3,572
  • 25
  • 36
0

I had a similar problem for Flutter, where my frameworks couldn't be resolved and I ended up here, so posting the solution to the problem in here.

Solution:

Update your pod version to match at least 1.12.1

Xcode 14.3 changed how they resolve symlinks to relative paths. So if you are below pod version 1.12.1 (mine was e.g. 1.11.3), if fails due to wrong path resolution and you either can go into: flutter-project/ios/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh

and change:

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

to

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

Or you update your pod version to match at least 1.12.1

Hope that helps someone searching for this problem in flutter and having the same error message.

Stefan Rein
  • 8,084
  • 3
  • 37
  • 37
-1

In my case i solved this issue by update xcode, so check the xcode if there is new update.

Taif Raoof
  • 354
  • 3
  • 8
-1

open a terminal > go to your project folder

flutter clean

flutter pub get

cd ios

pod install

//back to project folder
cd .. 

flutter run

or Build in your Xcode

This worked for me in Xcode 14.1

-1

xcode ->targets->runner-> build phases ->

Remove unwanted scripts like in my case i have firebase crashlytics

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 24 '23 at 08:14
-1

Today I faced the same issue and downloaded Xcode 14.1. It is working without any issues.

Download it from here

https://download.developer.apple.com/Developer_Tools/Xcode_14.1/Xcode_14.1.xip
MUHAMMED IQBAL PA
  • 3,152
  • 2
  • 15
  • 23