Flutter hot reload not working on my device - android

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. 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.
Any help would be highly appreciated, here is the flutter doctor -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

I had this exact problem with a Pixel 2. Fine one minute, then boom - hot reload / restart was not available. 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. Pressing r after flutter run also did nothing. Nothing significant happened in between it working and it not working - no updates to Android Studio, Flutter or the device. I tried restarting the device, Android Studio, flutter clean, I tried swapping the USB cable, nothing seemed to work.
It did eventually start working again: I did a flutter clean followed immediately by a reboot of my computer. 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:
In some files may be added file:/// before the file name in the above file. Search in the whole project and remove file:/// line and again import that package again.
flutter upgrade
Clean project(flutter clean)
I also change my emulator.
that worked for me

Since you have all necessary plugin installed and your flutter-doctor has no issues.
Try running the command flutter clean.
Hopefully that is going to work.
I hope this helps.

if you are using an android virtual device. navigate to its settings => proxy then untick 'Use android studio http proxy settings' select 'No proxy'... that worked for me.

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. (With VS Code hotkeys this is Ctrl+K or S)
Simply removing the "Ctrl+K, S" and replacing it with Ctrl+S worked after days of trying to fix this. 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.
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...
Thanks

I had the same problem, All you need to do:
Wipe data in the Android Emulator
Cold boot the device and done.

If you are still not able to figure it out check this method.
When you import widget from another .dart file. sometime android studio will import this path.
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

Related

Unable to run Flutter project on Android after update

I've been trying to get my Flutter project to run after upgrading it to 2.10.4 and it's been a headache from the start. The project runs fine on a browser, but I'm having difficulty running on an Android emulator. I think I'm at the last hurdle, but I'm stumped right now. I'm receiving this error when running on VS Code:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Failed to install the following SDK components:
build-tools;30.0.2 Android SDK Build-Tools 30.0.2
The SDK directory is not writable (C:\Program Files (x86)\Android\android-sdk)
Here's my Flutter Doctor:
PS D:\Documents\Flutter_Projects\glance> flutter doctor -v
[√] Flutter (Channel stable, 2.10.4, on Microsoft Windows [Version 10.0.19043.1586], locale en-US)
• Flutter version 2.10.4 at D:\Programs\flutter_windows_v1.2.1-stable\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c860cba910 (3 weeks ago), 2022-03-25 00:23:12 -0500
• Engine revision 57d3bac3dd
• Dart version 2.16.2
• DevTools version 2.9.2
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Program Files (x86)\Android\android-sdk
• Platform android-31, build-tools 30.0.3
• ANDROID_HOME = C:\Users\reff1\AppData\Local\Android\Sdk
• ANDROID_SDK_ROOT = C:\Users\reff1\AppData\Local\Android\Sdk
• Java binary at: D:\AndroidStudio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[X] Visual Studio - develop for Windows
X Visual Studio not installed; this is necessary for Windows development.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2021.1)
• Android Studio at D:\AndroidStudio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
[!] Android Studio (version 4.1)
• Android Studio at D:\Programs\AndroidStudio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
X Unable to determine bundled Java version.
• Try updating or re-installing Android Studio.
[√] VS Code, 64-bit edition (version 1.50.1)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.17.0
[√] Connected device (4 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 12 (API 32) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19043.1586]
• Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.88
• Edge (web) • edge • web-javascript • Microsoft Edge 99.0.1150.46
[√] HTTP Host Availability
• All required HTTP hosts are available
Here's the part that keeps getting me. I'm seeing I need to run flutter doctor --android-licenses and this is what I get:
PS D:\Documents\Flutter_Projects\glance> flutter doctor --android-licenses
Error: Could not find or load main class Files
I have no clue where to go from here. Any help would be greatly appreciated here. Thank you in advance.
It appears that you have two sets of Android Studio and Android SDK.
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Program Files (x86)\Android\android-sdk <--- 1
...
• ANDROID_HOME = C:\Users\reff1\AppData\Local\Android\Sdk <--- 2
[√] Android Studio (version 2021.1) <--- 1
• Android Studio at D:\AndroidStudio
...
[!] Android Studio (version 4.1) <--- 2
• Android Studio at D:\Programs\AndroidStudio
Android Studio version 4.1 is a bit older so I guess you installed it in the past and forgot about it.
Also, it is not normal (or up-to-date) to have Android SDK placed under Program Files.
This is the direct cause of the error. In Windows, writing files under Program Files requires administrator privileges.
Your system is possibly confused because you have a mixed environment with an SDK that requires administrator privileges and one that does not.
My advice is to first uninstall all of them.
Before you begin, find out where the Android Studio configuration files are stored and backup them.
It is documented in here.
Now, completely uninstall all versions of Android Studio and Android SDK, manually delete all environment variables related to Android if any, manually delete (and backup) all configuration files if the uninstaller did not, then make sure all four directories above are empty.
Next, install the latest version of Android Studio and install the Android SDK via Android Studio. At this point, make sure that the installation directory is not under Program Files or Program Files (x86). If it is, then something in the older version is still there and is doing bad things so you have to restart from the first step.
Finally, run flutter clean (just to be sure), then flutter doctor to make sure only one of each is detected.
In android studio update your sdk 30
Unable to determine bundled Java version.
• Try updating or re-installing Android Studio
See in your error in flutter doctor
Change the ownership of Android SDK:
sudo chown -R $(whoami) $ANDROID_HOME
For this issue : Android license status unknown.
Type in command prompt
flutter doctor --android-licenses
Type Yes/y/Y to accept licenses
Maybe it's an emulator specific issue, did you try to run it on a real device?
Regarding the android license issue you are getting, I guess that the system is not recognizing JAVA or it needs to be updated so please check that.
Also make sure that the emulator itself is updated and not only the android SDK, go to SDK manager and check all the dashed components:
If this didn't work, delete the emulator and create a new one, and if that didn't help, delete all instances of android studio as I see 2 on your system that might conflict the SDK path.

Device not applicable for the “main.dart” configuration

Before anyone points me to this link I would like to mention, that I don't think these are directly related.
As one can see my flutter doctor -v command is error free:
➜ flutter git:(stable) flutter doctor -v
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76, locale en-US)
• Flutter version 1.12.13+hotfix.9 at /Users/johannes/.flutter-cli/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.3)
• Android SDK at /Users/johannes/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• No issues found!
Yet I to have the issue of a grayed out emulator device with the message Device not applicable for the “main.dart” configuration like this:
I can now only start the emulator using the dropdown menu <no device> like this:
Interestingly I am then actually able to run my app on the device, while the device is still grayed out:
Flutters hot-reloading feature seems to not work properly though.
I have already added the main folder to the project as suggested here and I also made sure to change NO SDK to ANDROID API PLATFORM as suggested in the same link. All dependencies in Project Structure > Modules are found by Android Studio. I cloned the Flutter SKD from the stable branch on GitHub.
Does anyone have an idea why my setup is behaving this way?
Close Android Studio and Run again as Administrator
It solved my problem:
1- Make sure Flutter plugin is installed in android studio, you can install the plugin from file > setting > plugin
2- choose flutter SDK path from File > setting> Language & Framework > flutter.
I have the same issue before.
Uninstall Flutter and Dart plugin from Android Studio then reinstall Flutter (Dart will be installed automatically)
Remove created emulators from AVD Manager and create new one
Try making new project, and set SDK version same as emulators API version or lower from File > Project Structure...
Hopefully worked for you.

"flutter run" gets stuck at "Running Gradle task 'assembleDebug"

I updated Flutter to the latest stable version today - 1.12.13+hotfix.7 (I was running 1.12.13+hotfix.6 before). When I tried to run my project in vs code with flutter run it always gets stuck at Running Gradle task 'assembleDebug:
Have anyone experienced the same issue?
Here is the output of flutter doctor -v:
[georgi#georgi-pc Line-up-Generator]$ flutter doctor -v
[✓] Flutter (Channel stable, v1.12.13+hotfix.7, on Linux, locale en_GB.UTF-8)
• Flutter version 1.12.13+hotfix.7 at /home/georgi/Development/flutter
• Framework revision 9f5ff2306b (2 weeks ago), 2020-01-26 22:38:26 -0800
• Engine revision a67792536c
• Dart version 2.7.0
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /home/georgi/Android/Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 3.5)
• Android Studio at /opt/android-studio
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] Connected device (1 available)
• MI 8 • 62fb6fd8 • android-arm64 • Android 10 (API 29)
! Doctor found issues in 2 categories.
I have to point out that I have tried running flutter doctor --android-licenses but it gets stuck at 25%
Note: I am on Manjaro 18.1.5
UPDATE:
There seems to be an issue with Dart SDK: https://github.com/flutter/flutter/issues/49185#issuecomment-589968058
flutter clean worked for me
I had the same issue. I tried so many solutions and finally found on Github. Try this command in the terminal.
The issue has been resolved upstream. If you want to consume it you will have to switch to the master channel (for now. It will arrive in the stable channel at some point) by running
flutter channel master
After running that, I was able to build my apk just fine on Linux 5.5
I had the same problem and solved it.
I ran flutter doctor --android-licenses as sudo.
I used the whole path, don't know if that's necessary though.
For example I did it like that:
sudo /home/jan/development/languages+devtools/flutter/bin/flutter doctor --android-licenses
After that everything worked.
I tried every answer I found about it, but none of them worked.
Finally I fixed it by deleting the Android Virtual Device I had and creating a new one. In my case looks like it was a problem with the android emulator rather than a flutter bug.

Can't accept Android Licenses (Flutter)

Well, a month ago I was learning a bit of Flutter, and it was all fine, no problems, so, last week I lost everything in my PC, and need to format it, I did. So yesterday I tried install Flutter but, when accepting Android Licenses, it gave me this error:
Warning: File /home/damiani/.android/repositories.cfg could not be loaded.
To solve this i just touch .android/repositories.cfg and this message doesnt appear anymore, but now, when I flutter doctor --android-licenses it gave me this:
[========= ] 25% Fetch remote repository...
From this, I can't do anything, it just get stucked in there... Sometimes even give this:
[============================= ] 75% Computing updates...
Or this:
[======================= ] 58% Computing updates...
The longer it gets is here:
1 of 6 SDK package license not accepted.] 100% Computing updates...
Review license that has not been accepted (y/N)? y
1/
And from there, this message doesn't change...
When doing flutter doctor -v:
[✓] Flutter (Channel master, v1.14.7-pre.120, on Linux, locale pt_BR.UTF-8)
• Flutter version 1.14.7-pre.120 at /home/damiani/flutter
• Framework revision 82c00c915c (3 hours ago), 2020-02-05 06:35:49 -0800
• Engine revision 81dffd1241
• Dart version 2.8.0 (build 2.8.0-dev.7.0 c8ed304e97)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /home/damiani/Android/Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.3
• Java binary at: /var/lib/snapd/snap/android-studio/82/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Android Studio (version 3.5)
• Android Studio at /var/lib/snapd/snap/android-studio/82/android-studio
• Flutter plugin version 43.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)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
! Doctor found issues in 1 category.
No mood to continue with Flutter. Thanks since now...
sorry for bad english
os: arch linux
switching to flutter dev channel fixed the problem for me. run
flutter channel dev and then flutter upgrade and try
flutter doctor --android-licenses
Try to run the following commands,(It should ask you to accept the licenses)
sdkmanager --licenses
And also make sure to run the following
flutter config --android-sdk /pathToAndroidSdk --android-studio-dir /pathToAndroidStudio
After the above two commands I hope your problem should be resolved.
Thanks :)
This occurs because you haven't accepted all the android licenses.
Follow these steps, this worked for me.
Open console/terminal
Type flutter doctor --android-licenses
Accept every license that comes up, press y and you are good to go.

Emulator not authorized

Disclaimer: I am a newbie to using the emulators and flutter.
Question: How do I get flutter to connect to an emulator for debugging? Or, how do I create/set-up an emulated device properly so that my android studio flutter application recognizes it as a valid device?
I am not sure if it matters but I am currently working behind a proxy server. However, I have already added the appropriate certificates to the android ide.
The emulator I created is a Pixel 2, with API-28. I set it to allow developer options.
Using the new project part of the IDE I created a new flutter project in offline mode.
I expected the application to open in debug mode on my emulator but instead it says it doesn't think any device is connected. I ran flutter doctor and this is the output I received.
F:\SDKs\flutter_windows_v1.5.4-hotfix.2-stable\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 6.1.7601], locale en-US)
• Flutter version 1.5.4-hotfix.2 at F:\SDKs\flutter_windows_v1.5.4-hotfix.2-stable\flutter
• Framework revision 7a4c33425d (8 weeks ago), 2019-04-29 11:05:24 -0700
• Engine revision 52c7a1e849
• Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
• Android SDK at C:\Users\SWahlin-Rhoades\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.0
• Java binary at: F:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.
[√] Android Studio (version 3.4)
• Android Studio at F:\Program Files\Android\Android Studio
• Flutter plugin version 36.1.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[!] Connected device
• Device emulator-5554 is not authorized.
You might need to check your device for an authorization dialog.
! Doctor found issues in 1 category.
Process finished with exit code 0
I am aware of the thread device-emulator-55-is-not-authorized-android however, it didn't solve my problem. Within the thread it doesn't specify what new AVD was created in the solution and the other option of turing on developer settings didn't work.
I took another look at the Device_emulator_5554 answer and attempted to create another emulator Nexus S API 28 and I can now use it for debugging.

Categories

Resources