fluttercommunity / flutter_workmanager

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

Release mode error #422

Closed mehmetext closed 2 years ago

mehmetext commented 2 years ago

Version

Technology Version
Workmanager version ^0.5.0

Describe the error The workmanager works debug mode with no problem but when I do "flutter run --release" on my phone, I get there errors:

√  Built build\app\outputs\flutter-apk\app-release.apk (7.9MB).
Installing build\app\outputs\flutter-apk\app.apk...                10,3s

E/flutter ( 6234): [ERROR:flutter/shell/common/shell.cc(93)] Dart Error: Dart_LookupLibrary: library 'package:my_project/services/background_service.dart' not found.
E/flutter ( 6234): [ERROR:flutter/runtime/dart_isolate.cc(668)] Could not resolve main entrypoint function.
E/flutter ( 6234): [ERROR:flutter/runtime/dart_isolate.cc(167)] Could not run the run main Dart entrypoint.
E/flutter ( 6234): [ERROR:flutter/runtime/runtime_controller.cc(385)] Could not create root isolate.
E/flutter ( 6234): [ERROR:flutter/shell/common/shell.cc(604)] Could not launch engine with configuration.
E/flutter ( 6234): [ERROR:flutter/shell/common/shell.cc(93)] Dart Error: Dart_LookupLibrary: library 'package:my_project/services/background_service.dart' not found.
E/flutter ( 6234): [ERROR:flutter/runtime/dart_isolate.cc(668)] Could not resolve main entrypoint function.
E/flutter ( 6234): [ERROR:flutter/runtime/dart_isolate.cc(167)] Could not run the run main Dart entrypoint.
E/flutter ( 6234): [ERROR:flutter/runtime/runtime_controller.cc(385)] Could not create root isolate.
E/flutter ( 6234): [ERROR:flutter/shell/common/shell.cc(604)] Could not launch engine with configuration.

Output of flutter doctor -v


[✓] Flutter (Channel stable, 3.3.0, on Microsoft Windows [Version 10.0.22000.856], locale tr-TR)
    • Flutter version 3.3.0 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ffccd96b62 (6 days ago), 2022-08-29 17:28:57 -0700
    • Engine revision 5e9e0e0aa8
    • Dart version 2.18.0
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\Mehmet\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✗] Visual Studio - develop for Windows
    ✗ 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.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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.12+7-b1504.28-7817840)

[✓] VS Code (version 1.71.0)
    • VS Code at C:\Users\Mehmet\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.46.0

[✓] Connected device (5 available)
    • SM N935F (mobile)       • ce10171a7aba8c3103 • android-arm64  • Android 9 (API 28)
    • sdk gphone x86 (mobile) • emulator-5554      • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows            • windows-x64    • Microsoft Windows [Version 10.0.22000.856]
    • Chrome (web)            • chrome             • web-javascript • Google Chrome 104.0.5112.102
    • Edge (web)              • edge               • web-javascript • Microsoft Edge 104.0.1293.70

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

! Doctor found issues in 1 category.```
mehmetext commented 2 years ago

I fixed this error by adding @pragma('vm:entry-point') on a top line of headless callbackDispatcher function. So like this:

@pragma('vm:entry-point')
void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
    print("Native called background task: $task");
    ....
    return Future.value(true);
  });
}
hahastudio commented 2 years ago

I met the exact same issue and this works for me too!

TheCarpetMerchant commented 2 years ago

Same, waiting on confirmation from production. @ened This is probably due to the latest Dart SDK shipped with Flutter 3. Please update the readme to mention this issue, it could help a lot of people !

AdamBridges commented 2 years ago

I fixed this error by adding @pragma('vm:entry-point') on a top line of headless callbackDispatcher function. So like this:

@pragma('vm:entry-point')
void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
    print("Native called background task: $task");
    ....
    return Future.value(true);
  });
}

Yeah, this works. Thanks for that! Although, this issue probably shouldn't be closed until this is corrected either with Flutter/Dart or within the plugin itself, if possible. In addition, I was experiencing this issue in my debug build, so it's not only affecting release builds. @mehmetext