Al C
Al C

Reputation: 5377

Why aren't changes saved to device after hot reload?

Sometimes I'll write and save some code, Android Studio hot reloads my attached (Android) device, and the changes work as expected. However, if I stop the program on the phone or disconnect the device from Android Studio, the changes are not present--the program looks or works the way it did before I hot reloaded changes. It's as if the changes were in the phone's memory, but not saved as part of the APK on the device. ... Is this the expected behavior? (If so, what setting changes behavior so reloaded code is compiled and saved as part of the APK loaded on the attached phone device?)

I have Android Studio 3.5.3. I did see this post, but it's a few years old now, and I do see my changes; they're just not saved on the device.

Upvotes: 1

Views: 680

Answers (2)

Arsh Shaikh
Arsh Shaikh

Reputation: 1231

When you hot reload, flutter just updates it virtually, that's the reason it works so fast.

If you want to maintain your changes you have two options:

  1. Before disconnecting your phone re-run the app(Complete rebuild NOT hot reload)

    OR

  2. Run flutter run --release in the terminal, this will create a debug apk for your app.

Hope that helps.

Upvotes: 4

Michael Yuwono
Michael Yuwono

Reputation: 2617

In debug mode, Flutter app runs on a Dart VM, and hot reload is just reloading the VM, not reinstalling the actual APK.

Upvotes: 2

Related Questions