Learn Pain Less

HomeOur TeamContact
Flutter
Flutter WorkManager not working in Release mode (Working in Debug mode)
Pawneshwer Gupta
Pawneshwer Gupta
September 06, 2022
1 min
Flutter WorkManager not working in Release mode (Working in Debug mode)

If you are using flutter_workmanager plugin in flutter then probably you may face an issue that WorkManager works fine in Debug mode but in Release mode WorkManager failed to run tasks in background. or sometimes could not launch engine with configuration

Its impossible to trace logs on release apk, so instead of building release apk and installing in device. Add “—release” argument while running app so that you can run release app in device and trace logs as well.

And if you look into logs you will see below issue.

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.

So according to logs WorkManager failed to call our headless callbackDispatcher function.

Solution

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

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

Now try to run app in release mode and now WorkManager will work fine as expected.

Learn Flutter in 90 days with Pawneshwer!

Dart Beginners Course in Hindi free of cost for limited period.

Start Learning

250+

LESSONS

30+

COURSES

15+

TUTORS

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Tags

WorkManager

Share


Pawneshwer Gupta

Pawneshwer Gupta

Software Developer

Pawneshwer Gupta works as a software engineer who is enthusiastic in creating efficient and innovative software solutions.

Expertise

Python
Flutter
Laravel
NodeJS

Social Media

Related Posts

[Solved] Fixing cmdline-tools component is missing Error in Flutter
[Solved] Fixing cmdline-tools component is missing Error in Flutter
August 03, 2023
1 min
Learn Pain Less  © 2024, All Rights Reserved.
Crafted with by Prolong Services

Quick Links

Advertise with usAbout UsContact Us

Social Media