fluttercommunity / flutter_workmanager

A Flutter plugin which allows you to execute code in the background on Android and iOS.
859 stars 276 forks source link

🐞[Android] execution of the `callBackDispatcher` destroys another library's platform channel #430

Open clangenb opened 2 years ago

clangenb commented 2 years ago

Version

Technology Version
Workmanager version 5.0.0

Describe the error Executing a periodic task destroys the platform channel of another library in_app_webview.

E/flutter (17528): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method evaluateJavascript on channel com.pichillilorenzo/flutter_inappwebview_1214122967374174233124163190134233129107185174)
E/flutter (17528): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294:7)
E/flutter (17528): <asynchronous suspension>
E/flutter (17528): #1      InAppWebViewController.evaluateJavascript (package:flutter_inappwebview/src/in_app_webview/in_app_webview_controller.dart:1420:16)
E/flutter (17528): <asynchronous suspension>
E/flutter (17528): 

I am quite positive that this is the issue because the flutter_inappwebView is launched correctly and has been working stable for months before introducing the workmanager. I will investigate some more...

Output of flutter doctor -v [√] Flutter (Channel stable, 3.3.2, on Microsoft Windows [Version 10.0.22000.978], locale en-CH) • Flutter version 3.3.2 on channel stable at C:\tools\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision e3c29ec00c (2 weeks ago), 2022-09-14 08:46:55 -0500 • Engine revision a4ff2c53d8 • Dart version 2.18.1 • DevTools version 2.15.0

[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0) • Android SDK at C:\Users\clang\AppData\Local\Android\sdk • Platform android-33, build-tools 32.0.0 • Java binary at: C:\Users\clang\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\213.7172.25.2211.8571212\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\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.3) • Android Studio at C:\Users\clang\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\213.6777.52.2113.8172706 • Flutter plugin version 64.1.4 • Dart plugin version 213.5744.122 • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[√] Android Studio (version 2022.1) • Android Studio at C:\Users\clang\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\213.7172.25.2211.8571212 • Flutter plugin version 70.0.3 • Dart plugin version 213.7371 • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[√] Connected device (6 available) • Mi 9T (mobile) • 3d64a078 • android-arm64 • Android 10 (API 29) • SM G800F (mobile) • 52009a2368692331 • android-arm • Android 6.0.1 (API 23) • Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22000.978] • Chrome (web) • chrome • web-javascript • Google Chrome 105.0.5195.127 • Edge (web) • edge • web-javascript • Microsoft Edge 105.0.1343.50

[√] HTTP Host Availability • All required HTTP hosts are available

clangenb commented 2 years ago

The cause seems to be different. It is the actual execution of the callBackDispatcher, which destroys the channel. I updated the issue accordingly.

dominicmh commented 9 months ago

We faced a similar issue. Just instead of in_app_webview, it kills the BLE connection of flutter_reactive_ble in our case. Apparently, the engine?.destroy() in BackgroundWorker.kt is responsible for this. Removing this line fixes this issue. @clangenb, if you're still facing this issue with in_app_webview, can you confirm?

What's the purpose of destroying the engine? Since other platform channels seem to reuse it, is it possible it should be created differently?

clangenb commented 9 months ago

We have stopped using the workmanager and the webview since a long time now, so I can't make a statement unfortunately.