futureware-tech/flutter_sentry

WillPopScope Android crash

fabricio-sisplan opened this issue · 4 comments

On android using the SystemNavigator.pop() to close the app causes a crash;

Launching lib\main.dart on G6 in debug mode...
✓ Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:62634/_UpFuP1mSRo=/ws
D/ (22484): Gralloc Register w:720, h:1344, f:0x1, usage:0xb00, ui64Stamp:1762467, sSize:3870720, line = 2106
D/ (22484): Gralloc Register w:720, h:1344, f:0x1, usage:0xb00, ui64Stamp:1762492, sSize:3870720, line = 2106
D/ (22484): Gralloc UnRegister w:720, h:1344, f:0x1, usage:0xb00, ui64Stamp:1762409 line = 2218
D/ (22484): Gralloc UnRegister w:720, h:1344, f:0x1, usage:0xb00, ui64Stamp:1762492 line = 2218
D/ (22484): Gralloc UnRegister w:720, h:1440, f:0x1, usage:0xb00, ui64Stamp:1762411 line = 2218
D/ (22484): Gralloc UnRegister w:720, h:1440, f:0x1, usage:0xb00, ui64Stamp:1762428 line = 2218
D/AndroidRuntime(22484): Shutting down VM
E/AndroidRuntime(22484): FATAL EXCEPTION: main
E/AndroidRuntime(22484): Process: br.com.sisplansistemas.aplicativo, PID: 22484
E/AndroidRuntime(22484): java.lang.RuntimeException: Unable to destroy activity {br.com.sisplansistemas.aplicativo/br.com.sisplansistemas.aplicativo.MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property channel has not been initialized
E/AndroidRuntime(22484): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4535)
E/AndroidRuntime(22484): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4553)
E/AndroidRuntime(22484): at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:39)
E/AndroidRuntime(22484): at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
E/AndroidRuntime(22484): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
E/AndroidRuntime(22484): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
E/AndroidRuntime(22484): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(22484): at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime(22484): at android.app.ActivityThread.main(ActivityThread.java:6880)
E/AndroidRuntime(22484): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(22484): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:504)
E/AndroidRuntime(22484): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/AndroidRuntime(22484): Caused by: kotlin.UninitializedPropertyAccessException: lateinit property channel has not been initialized
E/AndroidRuntime(22484): at org.dasfoo.flutter_sentry.FlutterSentryPlugin.onDetachedFromEngine(FlutterSentryPlugin.kt:68)
E/AndroidRuntime(22484): at io.flutter.embedding.engine.FlutterEnginePluginRegistry.remove(FlutterEnginePluginRegistry.java:252)
E/AndroidRuntime(22484): at io.flutter.embedding.engine.FlutterEnginePluginRegistry.remove(FlutterEnginePluginRegistry.java:260)
E/AndroidRuntime(22484): at io.flutter.embedding.engine.FlutterEnginePluginRegistry.removeAll(FlutterEnginePluginRegistry.java:268)
E/AndroidRuntime(22484): at io.flutter.embedding.engine.FlutterEnginePluginRegistry.destroy(FlutterEnginePluginRegistry.java:112)
E/AndroidRuntime(22484): at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:360)
E/AndroidRuntime(22484): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach(FlutterActivityAndFragmentDelegate.java:522)
E/AndroidRuntime(22484): at io.flutter.embedding.android.FlutterActivity.onDestroy(FlutterActivity.java:578)
E/AndroidRuntime(22484): at android.app.Activity.performDestroy(Activity.java:8865)
E/AndroidRuntime(22484): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1331)
E/AndroidRuntime(22484): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4520)
E/AndroidRuntime(22484): ... 11 more
D/HprofFactory(22484): Create HprofDebugEx
I/Process (22484): Sending signal. PID: 22484 SIG: 9
Lost connection to device.
Exited (sigterm)

Yes I ran into this as well, the bug is happening here https://github.com/futureware-tech/flutter_sentry/blob/master/android/src/main/kotlin/org/dasfoo/flutter_sentry/FlutterSentryPlugin.kt#L75

The private lateinit var channel: MethodChannel is never initialized and when detaching from the engine it throws

kotlin.UninitializedPropertyAccessException: lateinit property channel has not been initialized

@fabricio-sisplan This has nothing to do with WillPopScope, it always happens when the app is closed.

Ah, pardon my attempts to use Kotlin constructs. I'll send a fix shortly, or please feel free to send in a PR.

I'll open a PR soon.