5

Yesterday, I created a flutter project named sample1. and I worked fine. but when I tried to open the file today and try to run it, I got an error.

the log says

Running "flutter pub get" in sample1...                            603ms
Launching lib/main.dart on iPhone 8 in debug mode...
Running pod install...                                           1,313ms
Running Xcode build...                                                  
Xcode build done.                                           11.8s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳

    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Analyzing workspace
    note: Constructing build description
    note: Build preparation complete
    warning: Capabilities for Signing & Capabilities may not function correctly because its entitlements use a placeholder team ID. To resolve
    this, select a development team in the Runner editor. (in target 'Runner' from project 'Runner')

Could not build the application for the simulator.
Error launching application on iPhone 8.

I think I have tried everything written here, except the ones like

pub upgrade
pub run

because it says

zsh: command not found: pub

Could not build the application for the simulator. Error launching application on iPhone 11 Pro Max

The android version is working fine. Please kindly help me. Thank you

EDIT** I just created a new project and it seemed to be working fine but I am afraid it won't work next time I open it.

Abel
  • 113
  • 2
  • 9

4 Answers4

6

Before Anything you will first need to Run a successful Xcode build on your desired iOS device or Simulator directly from Xcode!

If you've successfully done so head over to : the instructions to run with Hot Reload⚡️ on iOS from VsCode & Android Studio

If not - Follow this 8 steps to getting your Xcode Build Up & Running ->

1. Open Xcode - do all the classic Set Up (Signing in with your dev account as a Team & choosing a UNIQUE bundle Identifier)

S.Shot Xcode Signing & Capabilities

2. If you don't have cocoapods Installed on your Mac :

From terminal cd ~

then : for M1 Mac run the following :

arch -x86_64 sudo gem install ffi
sudo gem install cocoapods

while for intel macs just run :

sudo gem install cocoapods

3. Now once you have cocoapods installed on your machine
cd yourflutterprojectroot

flutter clean
flutter pub get

4. Update & install pods :

for M1 Macs :

cd ios
arch -x86_64 pod update
pod install
arch -x86_64 pod update

for intel macs :

cd ios
pod update
pod install
pod update

5. Connect your iPhone (if you want to run on real device)

In your iPhone Settings - set Auto-Lock to Never (& Unlock it !) - Connect your iPhone or iPad to Mac with USB cable & Accept Prompt "Trust Computer" on the iPhone

S.Shot iPhone Prompt


6. Run Xcode Build from Xcode make sure to Select your device or simulator

Select device in Xcode & Run

After running this alert should prompt select Ok

S.Shot Xcode Could not Launch "Runner"

if this alert didn't prompt & build failed totally Try setting your Runner > Info > Configurations like this but first try to see if you can do step 7 - if you can do it don't change anything


7. In your iPhone Settings > General > A New Menu will have appeared - Navigate to it & Click « Verify App » or « Accept »

Developer iPhone Settings

8. Now Run Xcode Build Again - it should build

Xcode Build is done



Now -

You've done everything successfully ✨ - congrats - it works -

  • But what if you wanted to run directly from VSCode or Android Studio ?

It would make to long of a post - so i've split my answer for this second question :

find here the instructions to run with Hot Reload⚡️ on iOS from VsCode & Android Studio

See you there !


Aristidios
  • 1,921
  • 2
  • 13
  • 24
2

Run command like flutter pub upgrade not just pub upgrade.

Jarvis098
  • 1,420
  • 1
  • 11
  • 16
  • Thank you. I've just try `rm ios/Podfile` and `flutter pub upgrade` but it still doesn't work. – Abel Jul 20 '21 at 01:48
2

Your first question was on running your flutter app on iOS - you've done so by running your first Xcode Build : )

Now - I'll answer for both VSCode & Android Studio - your second question :

How do i run my Flutter App with Hot Reload ⚡️ on a Real iOS device or Simulator ?

To get started you will first need to follow the instruction in my first answer & run a successful Xcode Build - directly from Xcode


Once you've done so follow this steps :


    • Make sure your device is still connected & unlocked - Run flutter devices in Terminal :

It will tell you if your device or Simulator is detected (it should be since you've just done a successful Xcode build)


  1. Open back your flutter project in VsCode or Android Studio & make sure your device is still unlocked - open a new simulator only if you want to run on Simulator

Do a first Hot Reload⚡️ using Terminal Commands :

Run flutter run in your flutter project root or run flutter run -d yourDeviceID if it does not directly run on your iOS device or Simulator

You will find your iOS device ID here :

Picture of Menu to find Device ID

Select Add Additional Simulators

Picture Device ID

After running flutter run or flutter run -d yourDeviceID an error will prompt if it's your first time running

Error Allow Developer to open App

Press Cancel & go to your Mac > Systems Preferences > Security & Privacy - & allow the file to execute

Security & Privacy Screen

then wait a bit the app might launch on it's own or try flutter run again or flutter run -d yourDeviceID

Once successful you can now use Hot Reload by pressing r in terminal

  • to Hot Reload On Save in VsCode or Android Studio - follow bellow instructions :

HotReload Tab

Hot Reload⚡️Using VsCode :

Press F8 or Select ▷ « Start Debugging » in main.dart

That’s it ! You now have the power of Hot Reload⚡️ with VsCode on a physical device !

Hot Reload⚡️on Android Studio :

Select your iOS device & run (it should appear if you've followed everyting correctly)



Aristidios
  • 1,921
  • 2
  • 13
  • 24
1

You should try go to flutter/bin/cache delete cache folder inside bin folder then run flutter upgrade then flutter doctor and rerun your app

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
  • Thank you for your comment. I though it could work but it didn't. it still has the same error. – Abel Jul 20 '21 at 03:22
  • the error occurred probably because I didn't set anything for iOS on Xcode. as the other person told me I set an identifier and it worked. – Abel Aug 24 '21 at 07:41