pushy / pushy-flutter

The official Pushy SDK for Flutter apps.
Apache License 2.0
21 stars 19 forks source link

Installing background listener fails in release mode #48

Closed ilaurillard closed 2 years ago

ilaurillard commented 2 years ago

Running the example in --release mode leads to the following errors:

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

Any help is appreciated!

(.. changed the deprecated FlatButton to an ElevatedButton in the example code)

My setup is:

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.1, on Debian GNU/Linux 11 (bullseye) 5.10.0-18-amd64, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) [✓] Chrome - develop for the web [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.71.0) [✓] Connected device (3 available) [✓] HTTP Host Availability

pushy commented 2 years ago

Hi @ilaurillard, Thanks for reaching out. We'd be glad to assist.

This might have to do with Dart code obfuscation in newer versions of Flutter.

Can you please try replacing the contents of pushy-flutter/lib/pushy_flutter.dart in your cloned project with these contents and then rebuild and run the sample app to see if it resolves the issue?

ilaurillard commented 2 years ago

Hi there,

thank you for looking into my issue.

I replaced the library code, and my project starts fine without the above errors. Receiving messages works as expected.

So i replaced the pushy dependency with the fork:

pushy_flutter: ^2.0.8

pushy_flutter: git: url: https://github.com/oexza/pushy-flutter

No errors, anymore, when installing the listener.


But ... when my app gets terminated, i do not get notifications anymore:

I/flutter ( 8654): Pushy: _isolate() received notfication E/flutter ( 8654): [ERROR:flutter/shell/common/shell.cc(93)] Dart Error: Dart_LookupLibrary: library 'package:iftnord_ffit_app/Service/PushyBackground.dart' not found.


Do you have any further ideas?

ilaurillard commented 2 years ago

then i put the background method into the main.dart file and it gets slightly better.

For a terminated App i get the:

09-14 23:15:43.340 12996 13030 I flutter : Pushy: _isolate() received notfication

but my method wont get called .. at least no debug prints in the logs and Pushy.notify wont throw any popups

ilaurillard commented 2 years ago

Ok .. i downgraded to Flutter 3.0.5 and it seems to work again.

Bug would have been introduced since Flutter 3.1.0

Thanks for your efforts so far,

please let me know if there is any progress concerning this topic

pushy commented 2 years ago

Hi @ilaurillard, Thanks for your efforts with investigating this issue.

We've just updated to the latest stable release of Flutter (3.3.2) and ran the example app without making any changes apart from migrating FlatButton to ElevatedButton, and it just worked, including notification delivery handling via background isolate (app swiped away).

It could be that this bug is only present in older versions of the Flutter SDK such as 3.1.0, and that upgrading Flutter to 3.3.2 will resolve the issue for you.

Please run the following commands to update to the latest Flutter stable version:

flutter channel stable
flutter upgrade

Also, please restore the original contents of pushy-flutter/lib/pushy_flutter.dart before testing again.

Please let us know if this indeed resolves the issue for you.

ilaurillard commented 2 years ago

Hello @pushy

Are you sure, you compiled in --release mode? In debug or profile mode everything runs as expected ...

The problem first occured on 3.1.x i think - Upgrades to 3.2.x and 3.3.x did not fix it for me.

I just pulled your changes, upgraded to newest stable and tried again:

Flutter 3.3.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision e3c29ec00c (16 hours ago) • 2022-09-14 08:46:55 -0500
Engine • revision a4ff2c53d8
Tools • Dart 2.18.1 • DevTools 2.15.0
~/pushy-flutter/example$ flutter run --release
Running "flutter pub get" in example...                            935ms
Launching lib/main.dart on Nokia 7 2 in release mode...
...
I/flutter (26778): Device token: de8641c6875e6f32cb1c18
E/flutter (26778): [ERROR:flutter/shell/common/shell.cc(93)] Dart Error: Dart_LookupLibrary: library 'package:pushy_flutter/pushy_flutter.dart' not found.
E/flutter (26778): [ERROR:flutter/runtime/dart_isolate.cc(668)] Could not resolve main entrypoint function.
E/flutter (26778): [ERROR:flutter/runtime/dart_isolate.cc(167)] Could not run the run main Dart entrypoint.
E/flutter (26778): [ERROR:flutter/runtime/runtime_controller.cc(385)] Could not create root isolate.
E/flutter (26778): [ERROR:flutter/shell/common/shell.cc(604)] Could not launch engine with configuration.

I will put some more time into it, trying gradle/android sdk updates, other mobile devices, different host system, but then i fear, i have to pin on 3.0.x for now and try again another time.

Thank you so far!

ilaurillard commented 2 years ago

Had another try with

$ flutter build apk --no-obfuscate --split-per-abi
$ adb install ...app-armeabi-v7a-release.apk
$ adb logcat | grep ushy

no success, so it seems, problem might not be related to obfuscating the app ...

09-15 08:14:55.870 27737 27737 D Pushy   : Initializing FlutterBackgroundExecutor background isolate
09-15 08:14:55.902 27737 27795 E flutter : [ERROR:flutter/shell/common/shell.cc(93)] Dart Error: Dart_LookupLibrary: library 'package:pushy_flutter/pushy_flutter.dart' not found.
pushy commented 2 years ago

Hi @ilaurillard , Thanks for your patience and further investigation.

We've managed to reproduce the issue when running with flutter run --release, and managed to resolve it in https://github.com/pushy/pushy-flutter/commit/57a2178dadb5fccee84861438dc258bc43050f90 and published a new version of the Pushy Flutter SDK.

1) Please update the Pushy Flutter SDK in your app by editing the pubspec.yaml in the root directory of your project and updating the pushy_flutter package version to 2.0.9:

pushy_flutter: 2.0.9

2) Run flutter pub get to fetch the new version of our SDK.

3) Please add the following line of code to your lib/main.dart, right above the void backgroundNotificationListener() method declaration:

@pragma('vm:entry-point')

Please run your app and let us know if the problem is indeed resolved.

ilaurillard commented 2 years ago

Well, thank you so much!

Works fine!