How to clear Flutter's Build cache?
DartFlutterDart Problem Overview
There seems to be a problem with flutter's build.
I always need to perform RUN > Flutter Full Restart everytime I run the app to an emulator or device.
Otherwise, the app loads a scaffold body which my code had from 2 weeks ago when I first started coding it.
Here's the current source on pastebin
children: <Widget>[
new Opacity(
opacity: loader_visible ? 1.0 : 0.0,
child:
new Container(
padding: const EdgeInsets.all(32.0),
child: new CircularProgressIndicator()
)
),
while here is the resulting render tree:
I'm guessing flutter has cached the old code and never bothered replacing it with the new one, but I am not sure how it's Hot Reload was implemented. Anyways, I don't think that it is necessary to load the old cache when we have already performed a full rebuild.
Dart Solutions
Solution 1 - Dart
You can run flutter clean
.
But that's most likely a problem with your IDE or similar, as flutter run creates a brand new apk. And hot reload push only modifications.
Try running your app using the command line flutter run
and then press r
or R
for respectively hot-reload and full-reload.
Solution 2 - Dart
Solution 3 - Dart
There are basically 3 alternatives to cleaning everything that you could try:
flutter clean
will delete the/build
folder.- Manually delete the
/build
folder, which is essentially the same asflutter clean
. - Or, as @Rémi Roudsselet pointed out: restart your IDE, as it might be caching some older error logs and locking everything up.
Solution 4 - Dart
I found a way to automate running the clean before you debug your code. (Warning, this runs everytime you hit the button, even for hot restart)
-
First, find the Run > Edit Configurations Menu
-
Click the External tool '+' icon under Before launch: External tool, Activate tool window.
-
Run External Tool
-
Configure it like so. Put the working directory as a directory in your project.
Solution 5 - Dart
Build cache is generated on application run time when a temporary file automatically generated in dart-tools folder, android folder and iOS folder. Clear command will delete the build tools and dart directories in flutter project so when we re-compile the project it will start from beginning. This command is mostly used when our project is showing debug error or running related error. In this answer we would Clear Build Cache in Flutter Android iOS App and Rebuild Project structure again.
-
Open your flutter project folder in Command Prompt or Terminal. and type
flutter clean
command and press enter. -
After executing flutter clean command we would see that it will delete the
dart-tools
folder,android
folder andiOS
folder in our application with debug file. This might take some time depending upon your system speed to clean the project.
For more info, see https://flutter-examples.com/clear-build-cache-in-flutter-app/
Solution 6 - Dart
Besides running flutter clean
... The IDE sometimes has its own cache,
If that still does not work try deleting the app from the emulator or using a new emulator. I believe the app itself might be the one caching part of the application.
Solution 7 - Dart
I tried flutter clean
and that didn't work for me. Then I went to wipe the emulator's data and voila, the cached issue was gone. If you have Android Studio you can launch the AVD Manager by following this Create and Manage virtual machine. Otherwise you can wipe the emulator's data using the emulator.exe command line that's included in the android SDK. Simply follow this instructions here Start the emulator from the command line.
Solution 8 - Dart
Same issue with mine.
New to Flutter. I'm using VS build-in terminal to do flutter run
, to run the app in iPhone. It gives me error Error when reading 'lib/student_model.dart': No such file...
, which is an old code version in my code. I have changed it to lib/model/student_model.dart
.
And I search this line 'lib/student_model.dart'in the project, it appears file
kernel_snapshot.d` containing it. So, it build the project with old code version.
For me, Flutter clean
is not working. Restart VS fix the issue, not sure the problem is due to Flutter or VS?
And I'm wondering if there is some command to just build flutter project without run?
Solution 9 - Dart
Or you can delete the /build folder under your /app-project folder manually if you cannot run flutter command.
Solution 10 - Dart
I was facing the same issue and i found out that I was having two terminals in visual studio code, On first terminal it was already running my flutter project and on the other terminal I was running different solutions shared in this thread. Due to this reason no solution was working for me. So there are two ways you can solve this problem. 1- Restart visual studio code (it will automatically close the terminals) 2- Stop the terminal in which flutter project is already running and then run flutter clean command.
Solution 11 - Dart
open your terminal in IDE type flutter clean and press Enter then hot Reload the project again