flutter_workmanager
flutter_workmanager copied to clipboard
🐞Not working on Android Release when obfuscated to show Local Notifications
Describe the bug I am trying to show local notifications from workmanager. It works fine when I run on my physical Android device locally, but when I build an appbundle obfuscating the code, it won't work nor throw errors. I've tried with Flutter Local Notifications and with Awesome Notifications. If I request to show notification from main thread, it works even when obfuscated the code. It won't work only if I call a Workmanager task and use the show method inside callbackdispatcher();
To Reproduce I've created a fresh application with implementation of packages Workmanager and Flutter Local Notifications.
- Clone this sample;
- Add key.porperties to sign the bundle;
- Run
flutter build appbundle --obfuscate --split-debug-info={$FOLDER}
to create a bundle (replace $FOLDER with existing location) - Install it on your Android device (You can use Internal App Sharing)
Expected behavior Local notification should be shown on app initialization
Sample code to reproduce the problem Sample Code
flutter doctor -v
[✓] Flutter (Channel stable, 2.10.4, on Linux Mint 20.3 5.4.0-107-generic, locale en_US.UTF-8) • Flutter version 2.10.4 at /home/bruno/_development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision c860cba910 (11 days ago), 2022-03-25 00:23:12 -0500 • Engine revision 57d3bac3dd • Dart version 2.16.2 • DevTools version 2.9.2
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /home/bruno/Android/Sdk • Platform android-31, build-tools 30.0.3 • Java binary at: /snap/android-studio/current/android-studio/jre/bin/java • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822) • All Android licenses accepted.
[✓] Chrome - develop for the web • Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop • clang version 10.0.0-4ubuntu1 • cmake version 3.16.3 • ninja version 1.10.0 • pkg-config version 0.29.1
[✓] Android Studio • Android Studio at /snap/android-studio/current/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 • android-studio-dir = /snap/android-studio/current/android-studio • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
[✓] VS Code (version 1.66.0) • VS Code at /usr/share/code • Flutter extension version 3.38.0
[✓] Connected device (2 available) • Linux (desktop) • linux • linux-x64 • Linux Mint 20.3 5.4.0-107-generic • Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.60
[✓] HTTP Host Availability • All required HTTP hosts are available
• No issues found!
Any updates on this?
I have the same issue for Android 12 only, but removing --obfuscate does not solve it. Everything runs perfectly on Android 10.
It is not only an issue with other plugins called by workmanager, rather running workmanager itself when obfuscating any App built with Flutter v2.10+.
Same issue in Flutter 3, workmanager doesn't even run the call back in obfuscated Apps, which is a blocker since we are unable to release Apps with obfuscation.
You can reproduce it with any obfuscated app, no need to create appbundle and upload to play store, just build an APK and install it on device
flutter build apk --obfuscate --split-debug-info=./build/app/outputs/obfuscation_symbols
Enabling workmanager debug shows notification but actual task is not run:
After 10 minutes it shows another notification for the same task, but again actual task is not run. Note it was a one time task. Looks like workmanager keeps on trying to run the job every 10 minutes which fails hence keeps on trying to run it forever.
Background plugin isolate log:
2022-06-03 19:56:02.589 29540-1486/? E/flutter: [ERROR:flutter/shell/common/shell.cc(93)] Dart Unhandled Exception:
NoSuchMethodError: No top-level getter 'Ild' declared.
Receiver: top-level
Tried calling: Ild, stack trace: Warning: This VM has been configured to produce stack traces that violate the Dart standard.
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 29540, tid: 1486, name Unknown
build_id: '8deece9b97153dcde758a3ce15c56eaf'
isolate_dso_base: 7830404000, vm_dso_base: 7830404000
isolate_instructions: 78306bc7f0, vm_instructions: 78306b8000
#00 abs 00000078306c5eb3 virt 00000000002c1eb3 _kDartIsolateSnapshotInstructions+0x96c3
2022-06-03 19:56:02.589 29540-1486/? E/flutter: [ERROR:flutter/runtime/dart_isolate.cc(668)] Could not resolve main entrypoint function.
2022-06-03 19:56:02.589 29540-1486/? E/flutter: [ERROR:flutter/runtime/dart_isolate.cc(167)] Could not run the run main Dart entrypoint.
2022-06-03 19:56:02.592 29540-1486/? E/flutter: [ERROR:flutter/runtime/runtime_controller.cc(382)] Could not create root isolate.
2022-06-03 19:56:02.592 29540-1486/? E/flutter: [ERROR:flutter/shell/common/shell.cc(600)] Could not launch engine with configuration.
I have the same issue, have you figured out a solution or a walkaround?
I think @ened maintains this plugin, he might have some workarounds, I haven't found any yet. I filed an issue in dart sdk repo https://github.com/dart-lang/sdk/issues/49181
Had the same problem. Task does not execute.
same as your case,Generate a debug build, which works fine.
It is not only an issue with other plugins called by workmanager, rather running workmanager itself when obfuscating any App built with Flutter v2.10+. Same issue in Flutter 3, workmanager doesn't even run the call back in obfuscated Apps, which is a blocker since we are unable to release Apps with obfuscation. You can reproduce it with any obfuscated app, no need to create appbundle and upload to play store, just build an APK and install it on device
flutter build apk --obfuscate --split-debug-info=./build/app/outputs/obfuscation_symbols
Enabling workmanager debug shows notification but actual task is not run:
After 10 minutes it shows another notification for the same task, but again actual task is not run. Note it was a one time task. Looks like workmanager keeps on trying to run the job every 10 minutes which fails hence keeps on trying to run it forever.
Background plugin isolate log:
2022-06-03 19:56:02.589 29540-1486/? E/flutter: [ERROR:flutter/shell/common/shell.cc(93)] Dart Unhandled Exception: NoSuchMethodError: No top-level getter 'Ild' declared. Receiver: top-level Tried calling: Ild, stack trace: Warning: This VM has been configured to produce stack traces that violate the Dart standard. *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** pid: 29540, tid: 1486, name Unknown build_id: '8deece9b97153dcde758a3ce15c56eaf' isolate_dso_base: 7830404000, vm_dso_base: 7830404000 isolate_instructions: 78306bc7f0, vm_instructions: 78306b8000 #00 abs 00000078306c5eb3 virt 00000000002c1eb3 _kDartIsolateSnapshotInstructions+0x96c3 2022-06-03 19:56:02.589 29540-1486/? E/flutter: [ERROR:flutter/runtime/dart_isolate.cc(668)] Could not resolve main entrypoint function. 2022-06-03 19:56:02.589 29540-1486/? E/flutter: [ERROR:flutter/runtime/dart_isolate.cc(167)] Could not run the run main Dart entrypoint. 2022-06-03 19:56:02.592 29540-1486/? E/flutter: [ERROR:flutter/runtime/runtime_controller.cc(382)] Could not create root isolate. 2022-06-03 19:56:02.592 29540-1486/? E/flutter: [ERROR:flutter/shell/common/shell.cc(600)] Could not launch engine with configuration.
Finally found a solution with the help of dart-lang team.
- You need to annotate workmanager callback e.g. bgCallback with pragma
@pragma('vm:entry-point')
- Secondly since workmanager PR #388 is not yet merged you should also add
DartPluginRegistrant.ensureInitialized();
in the callback to avoid, other plugins called by workmanager, receiving plugin not found exceptions
@pragma('vm:entry-point')
void bgCallback() {
// You need below line until PR 388 is merged
DartPluginRegistrant.ensureInitialized();
//...
}
Notif showing, but audio not
android/app/src/main/res/raw/file.mp3 playSound: true, sound: const RawResourceAndroidNotificationSound("file"),