Skip to content

Instantly share code, notes, and snippets.

@jeroen-meijer
Last active August 23, 2023 04:05
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jeroen-meijer/bc62dcc74e10e745be7b5790cf74edf0 to your computer and use it in GitHub Desktop.
Save jeroen-meijer/bc62dcc74e10e745be7b5790cf74edf0 to your computer and use it in GitHub Desktop.
Flutter Repair iOS - When your Flutter build comes up with weird Xcode errors, run this script from your Flutter project directory and it will clean out all the old iOS stuff and get your project dependencies fresh.
#!/bin/sh
# To run, download the script or copy the code to a '.sh' file (for example 'flutterrepair.sh') and run like any other script:
# sh ./flutterrepair.sh
# or
# sudo sh flutterrepair.sh
echo "Flutter Repair (by jeroen-meijer on GitHubGist)"
echo Cleaning project...
flutter clean 2>&1 >/dev/null
echo Updating Pod...
pod repo update
if ! ( "${PWD##*/}" == 'ios')
then cd ios
fi
echo Removing pod files...
rm -rf Podfile.lock Pods/ 2>&1 >/dev/null
cd ..
echo Removing cached flutter dependency files...
rm -rf .packages .flutter-plugins 2>&1 >/dev/null
echo Getting all flutter packages...
flutter packages get
cd ios
echo Running pod install...
pod install
cd ..
echo DONE!
@enyo
Copy link

enyo commented Apr 4, 2019

This seems a bit dangerous: if the ios directory isn't found, then it simply doesn't change dir, and continues the script. Wouldn't it be better to check at the beginning, and make sure it's invoked in the right directory?

I'd also suggest adding set -e at the start of the script, so it aborts if it encounters an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment