When working on a Mac with Flutter in Android Studio (Arctic Fox 2021.3.1 Patch 4 and XCode 13.1 and/or 13.2):
If you move the root folder of your Flutter project using Finder, then open it in Android Studio and run it, the original folder location is still re-written (multiple sub folders with empty contents, usually, but not always).
Also, the moved project will no longer build from within XCode.
This means that if you don’t know the final desired location for your project at the time you create it, you will not be able to move it without weird stuff happening.
How can you move a Flutter project that was created with Android Studio without it having weird side-effects?
More info on how to reproduce:
-
Close all IDEs
-
Open Android Studio
-
Using Android Studio, create a new default FLUTTER project using Java as the Android code choice
-
Using Android Studio, run this project on an Android Emulator
-
Using Android Studio, run this project on an IOS simulator
-
Using Android Studio, open the project in XCode (right-click ios folder and select FlutterOpen project in Xcode)
-
Using XCode, run the project on an IOS simulator
-
Close all IDEs
-
Using Finder, move the project folder to a new location that is at the same depth as its current folder, but with a different parent folder. Meaning if current location is: [root]/x/y/a/my_project_original, the destination would be: [root]/x/y/b/my_project_copy
-
delete the original folder and remember where it was
-
Using Android Studio, open the project from its new location
-
Using Android Studio, open the project in XCode (right-click ios folder and select FlutterOpen project in Xcode)
-
Attempt to run on IOS simulator
-
Using Finder, check to verify original folder location has NOT been re-written
-
Using Android Studio, run the project on Android emulator
2
Answers
Here are the steps I follow to move a project’s location on my mac :
The steps should be the same within XCode (in the main window, remove the old location from your recent projects, and Open the new location)
You can move your Flutter project anywhere, as long as you don’t move the files inside the project relative to each other.
A note about
pod install
: If you are immediately running from Xcode, you need to runpod install
inside theios
folder after adding a plugin to yourpubspec.yaml
. If you runflutter run
or use Android Studio to run it, that will runpod install
for you automatically. However, you don’t have to runpod install
after moving the project, I’ve just tested it.This only happens if you kept Android Studio open when moving the files. You shouldn’t open the old project reference in Android Studio, you should open the project using
File
>Open...
.If you provide the errors, that will help us help you.
I have not found any side effects of moving a Flutter project. Quit Android Studio if it is running, and open it using
File
>Open...
. Or if you are in terminal, run (if installed using Jetbrains toolbox)open -a ~/Applications/JetBrains Toolbox/Android Studio.app/