简体   繁体   English

Flutter 热重载在我的设备上不起作用

[英]Flutter hot reload not working on my device

On my device, flutter does not hot reload, I initially thought this was a problem with flutter or android studio or vs code but when I use a different device, the hot reload is working.在我的设备上,flutter 没有热重载,我最初认为这是 flutter 或 android 工作室或 vs 代码的问题,但是当我使用不同的设备时,热重载正在工作。 How do I resolve this, it's just been driving me crazy and I have already spent a lot of hours trying to figure this out.我该如何解决这个问题,这让我发疯了,我已经花了很多时间试图解决这个问题。

And btw, it was initially working on this device until it wasn't, and I have already restarted my phone, I have even reinstalled flutter, basically every suggestion from the internet I have tried but so far, no fruits.顺便说一句,它最初在这个设备上工作,直到它没有,我已经重新启动了我的手机,我什至重新安装了 flutter,基本上我尝试过互联网上的每一个建议,但到目前为止,没有任何结果。

Any help would be highly appreciated, here is the flutter doctor -v.任何帮助将不胜感激,这里是 flutter 医生 -v。

[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Linux, locale en_US.UTF-8)
• Flutter version 1.12.13+hotfix.9 at /home/hamisi/flutter
• Framework revision f139b11009 (5 weeks ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /home/hamisi/android
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /home/hamisi/android/
    • Java binary at: /home/hamisi/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Android Studio (version 3.5)
    • Android Studio at /home/hamisi/android-studio
    • Flutter plugin version 44.0.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (1 available)
    • LG H845 • LGH845e35cd375 • android-arm • Android 7.0 (API 24)

• No issues found!

The output from flutter run -v --trace-startup is https://pastebin.com/9X4S5LWr output 来自flutter run -v --trace-startuphttps://pastebin.com/9X4S5LWr

I had this exact problem with a Pixel 2. Fine one minute, then boom - hot reload / restart was not available.我在 Pixel 2 上遇到了这个确切的问题。很好一分钟,然后繁荣 - 热重新加载/重新启动不可用。 I could deploy the app to the device, but hot reload options were greyed out in Android Studio and hot reload keyboard shortcuts did nothing.我可以将应用程序部署到设备上,但热重载选项在 Android Studio 中显示为灰色,并且热重载键盘快捷键没有任何作用。 Pressing r after flutter run also did nothing.flutter run之后按r也没有任何作用。 Nothing significant happened in between it working and it not working - no updates to Android Studio, Flutter or the device.在它工作和不工作之间没有发生任何重大事件 - Android Studio、Flutter 或设备没有更新。 I tried restarting the device, Android Studio, flutter clean , I tried swapping the USB cable, nothing seemed to work.我尝试重新启动设备,Android Studio, flutter clean ,我尝试更换 USB 电缆,似乎没有任何效果。

It did eventually start working again: I did a flutter clean followed immediately by a reboot of my computer.它最终确实再次开始工作:我做了flutter clean ,然后立即重新启动计算机。 I have no idea if this was the fix, or whether it was just one of those random who-the-f-knows, but hopefully it will help anyone else.我不知道这是否是解决方案,或者它是否只是那些随机的谁知道的人之一,但希望它会对其他人有所帮助。

[√] Flutter (Channel stable, v1.17.0, on Microsoft Windows [Version 10.0.18362.778], locale en-GB)
    • Flutter version 1.17.0 at D:\flutter
    • Framework revision e6b34c2b5c (10 days ago), 2020-05-02 11:39:18 -0700
    • Engine revision 540786dd51
    • Dart version 2.8.1


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at C:\Users\james\AppData\Local\Android\sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] Connected device (1 available)
    • Pixel 2 • HT7C11A06689 • android-arm64 • Android 10 (API 29)

• No issues found!

I had this issue some days ago I did a couple of things:几天前我遇到了这个问题,我做了几件事:

  1. In some files may be added file:/// before the file name in the above file.在某些文件中,可能会在上述文件的文件名之前添加file:/// Search in the whole project and remove file:/// line and again import that package again.在整个项目中搜索并删除file:///行并再次再次导入该 package。

  2. flutter upgrade

  3. Clean project( flutter clean )清洁项目( flutter clean

  4. I also change my emulator .我也改变了我的emulator

that worked for me对我有用

if you are using an android virtual device.如果您使用的是 android 虚拟设备。 navigate to its settings => proxy then untick 'Use android studio http proxy settings' select 'No proxy'... that worked for me.导航到其设置 => 代理,然后取消勾选“使用 android 工作室 http 代理设置”select“无代理”...这对我有用。

For anyone else who runs into this issue and has installed VS Code Hotkeys/Keymap for Android Studio, the default VS Code hotkey for "Save All" will immediately stop hot reload from working.对于遇到此问题并已为 Android Studio 安装 VS Code 热键/键盘映射的任何其他人,“全部保存”的默认 VS Code 热键将立即停止热重载工作。 (With VS Code hotkeys this is Ctrl+K or S) (对于 VS Code 热键,这是 Ctrl+K 或 S)

Simply removing the "Ctrl+K, S" and replacing it with Ctrl+S worked after days of trying to fix this.经过几天的尝试解决此问题,只需删除“Ctrl+K,S”并将其替换为 Ctrl+S 即可。 Screenshot below.截图如下。 File -> Settings -> Keymap -> Search for "save"文件 -> 设置 -> 键盘映射 -> 搜索“保存”

Screenshot with Instructions (Settings -> Keymap)带有说明的屏幕截图(设置 -> 键盘映射)

HotReload was not working me as well, but I searched for it and found the solution. HotReload 对我也不起作用,但我搜索它并找到了解决方案。

When you click on the HotReload it will work only in the changes inside the Build() Widget, if your code is outside the build() widget then it will not work...当您单击 HotReload 时,它将仅在 Build() 小部件内的更改中起作用,如果您的代码在 build() 小部件之外,则它将不起作用...

Thanks谢谢

I had the same problem, All you need to do: 1. wipe data in the android emulator 2.cold boot the device and done.我遇到了同样的问题,您需要做的就是: 1. 擦除 android 仿真器中的数据 2. 冷启动设备并完成。

Since you have all necessary plugin installed and your flutter-doctor has no issues.由于您已经安装了所有必要的插件,并且您的flutter-doctor没有问题。

Try running the command flutter clean .尝试运行命令flutter clean Hopefully that is going to work.希望这会奏效。

I hope this helps.我希望这有帮助。

If you are still not able to figure it out check this method.如果您仍然无法弄清楚,请检查此方法。

When you import widget from another.dart file.当您从另一个.dart 文件导入小部件时。 sometime android studio will import this path. android studio 有时会导入此路径。

import file:///C:/kharag/.../.../< App Name >/lib/filename.dart

Hot reload and hot restart will not work in that case.在这种情况下,热重载和热重启将不起作用。 To fix that you should find and remove file path and replace with given path format below要解决此问题,您应该找到并删除文件路径并替换为下面的给定路径格式

import package:< App Name >/filename.dart

Note: To see the change stop your app and run again注意:要查看更改,请停止您的应用并再次运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM