Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: "Lost connection to device" error after Hot Reload

Here's the full error from the debug console:

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
I/FlutterActivityDelegate( 4158): onResume setting current activity to this
D/        ( 4158): HostConnection::get() New Host Connection established 0xdc74b680, tid 4178
D/EGL_emulation( 4158): eglMakeCurrent: 0xdc741300: ver 2 0 (tinfo 0xdc74c480)
F/libc    ( 4158): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xd in tid 4177 (Thread-2), pid 4158 (le.startupnamer)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/sdk_gphone_x86/generic_x86:9/PPP4.180612.007/4860066:userdebug/dev-keys'
Revision: '0'
ABI: 'x86'
pid: 4158, tid: 4177, name: Thread-2  >>> com.example.startupnamer <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xd
Cause: null pointer dereference
eax ca0a8aac  ebx ca0a8aac  ecx 0000000a  edx c9046c80
edi de6638d0  esi c90479f8
ebp c9046b58  esp c9046b58  eip c96e31d8
backtrace:
#00 pc 006981d8  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#01 pc 008f5b75  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#02 pc 008e87ea  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#03 pc 008f3ad6  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#04 pc 008e8b2f  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#05 pc 008ffb03  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#06 pc 008eb310  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#07 pc 008f3d98  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#08 pc 008e8b2f  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#09 pc 008eafc8  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#10 pc 008f997f  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#11 pc 008eaff8  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#12 pc 008fc81c  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#13 pc 008eaf69  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#14 pc 008f997f  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#15 pc 008eaff8  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#16 pc 008ef41e  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#17 pc 008f0570  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#18 pc 0091433e  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#19 pc 0092fad4  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#20 pc 00932f2a  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#21 pc 00934573  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#22 pc 00933d2b  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#23 pc 0093004a  /data/app/com.example.startupnamer-Doz3k_Pl0QfJtnmxYqiyHg==/lib/x86/libflutter.so
#24 pc 0000056b  <anonymous:c7680000>
Lost connection to device.
Exited (sigterm)

I'm using Visual Studio Code with the Flutter extension, but without the Dart extension. I'm also trying to run my Flutter app on an Android emulator, which is a Nexus 6 with API 28 x86. Emulated performance is set to "Hardware - GLES 2.0". The rest of the settings are left as default.

I Cold Boot the emulator before using it with Flutter, due to adb connection problems that prevent the emulator from loading if I start the emulator normally. Possibly not related, but good to note anyway.

Typing flutter doctor -v into the command line will show the following:

[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 10.0.17134.112], locale en-AU)
    • Flutter version 0.5.1 at C:\dev\flutter
    • Framework revision c7ea3ca377 (6 weeks ago), 2018-05-29 21:07:33 +0200
    • Engine revision 1ed25ca7b7
    • Dart version 2.0.0-dev.58.0.flutter-f981f09760

[√] Android toolchain - develop for Android devices (Android SDK 28.0.1)
    • Android SDK at C:\Android\android-sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.1
    • ANDROID_HOME = C:\Android\android-sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
    • All Android licenses accepted.

[√] Android Studio (version 3.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)

[√] IntelliJ IDEA Community Edition (version 2018.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.2
    • Flutter plugin version 26.0.2
    • Dart plugin version 181.4668.60

[!] VS Code, 64-bit edition (version 1.25.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[!] Connected devices
    ! No devices available

! Doctor found issues in 2 categories.

Now for the actual problem:

When I load my Flutter app, no matter what kind of state the code is in, the app launches from the state it was in when I saved it for the first time after creation. If I try to make any change to the code (I simply change the theme color) and try to Hot Reload, the app crashes with the error I posted above. Why does this happen, and what can I do to fix this?

There is no error when I load the project, or when I Hot Reload without making any change to the code.

Any help is appreciated.

EDIT: I'm unable to replicate this bug in Android Studio using the same project. This bug only appears in Visual Studio Code for me.

like image 451
Makoren Avatar asked Jul 10 '18 10:07

Makoren


People also ask

What happens when hot reload in flutter?

A code change has a visible effect only if the modified Dart code is run again after the change. Specifically, a hot reload causes all the existing widgets to rebuild. Only code involved in the rebuilding of the widgets is automatically re-executed. The main() and initState() functions, for example, are not run again.

How do you trigger hot reload in flutter?

Perform Hot Reload:Run your flutter editor from the app or using the command prompt. We can use hot reload in flutter debug mode. Once your flutter project has been created do some changes in your code and perform a hot reload. In windows, you can perform a hot reload using 'ctrl+\' or using the hot reload button.

How do I connect flutters with AVD?

Creating Connection Choose Device: Open your VS Code and from the bottom right corner of your home screen click on the Flutter Device option. Select Device: When you click on the Flutter Device icon, list of available devices will open up in the command palette. Select the emulator you just created.


1 Answers

I managed to fix that on my machine. What did the trick for me was to switch do stable channel and update flutter toos with:

-flutter upgrade

-flutter pub get    
like image 96
schaefer Avatar answered Oct 21 '22 03:10

schaefer