Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background Isolate broken on Flutter version 3.3.2 in release mode #245

Open
JoshJuncker opened this issue Sep 28, 2022 · 6 comments
Open

Comments

@JoshJuncker
Copy link

JoshJuncker commented Sep 28, 2022

I upgraded to flutter 3.3.2 from 3.0.5, and I get the following error in release mode. Debug mode works fine, and 3.0.5 works fine.
Note that the error only happens upon enqueueing a background upload. Not upon registering the backgroundHandler.
The error results in no callbacks getting called in the dart code (the backgroundHandler isn't ever called). Although you can see the plugin logs from the native code logging the status and completion of the actual upload.

2022-09-28 10:57:50.270160-0600 Runner[3606:1898388] [VERBOSE-2:shell.cc(93)] Dart Error: Dart_LookupLibrary: library 'package:shout_flutter/utilities/service_locator.dart' not found.
2022-09-28 10:57:50.270335-0600 Runner[3606:1898388] [VERBOSE-2:dart_isolate.cc(668)] Could not resolve main entrypoint function.
2022-09-28 10:57:50.270420-0600 Runner[3606:1898388] [VERBOSE-2:dart_isolate.cc(167)] Could not run the run main Dart entrypoint.
2022-09-28 10:57:50.271344-0600 Runner[3606:1898388] [VERBOSE-2:runtime_controller.cc(385)] Could not create root isolate.
2022-09-28 10:57:50.271429-0600 Runner[3606:1898388] [VERBOSE-2:shell.cc(604)] Could not launch engine with configuration.

Note that 'package:shout_flutter/utilities/service_locator.dart' is simply the dart file that contains the top level backgroundHandler function (copied directly from the readme).
It seems something is wrong when it tries to boot the isolate with the top level function. I don't know what might have changed with isolates and top level functions from flutter 3.0.5 to 3.3.2. But I am using the same version/ref of flutter_uploader in both cases.

flutter_uploader:
    dependency: "direct main"
    description:
      path: "."
      ref: HEAD
      resolved-ref: c27820c84e2a6269997fb61f2fd0736c0841a7bb
      url: "https://github.com/fluttercommunity/flutter_uploader"
    source: git
    version: "3.0.0-beta.4"
@RamunasO
Copy link

RamunasO commented Sep 30, 2022

You need to add @pragma('vm:entry-point') to your callback function, otherwise flutter will treeshake it in production. See flutter downloader docs for an example.

This also needs to be added to UploadTaskStatus class from flutter uploader side most likely, otherwise you will not be able to pass that class through the isolate.

@JoshJuncker
Copy link
Author

@RamunasO The flutter downloader docs also make it seem like the pragma entry is only required for Android, but my issue was happening on iOS.
@pragma('vm:entry-point') must be placed above the callback function to avoid tree shaking in release mode for Android.

I'll have to try it out and see if it works.

@waqadArshad
Copy link

Hi @JoshJuncker, did you find any solution? I am also having this issue. It is not working on release mode. Can you please help me out?

@JoshJuncker
Copy link
Author

@waqadArshad I just downgraded to flutter 3.0.5. Not a great solution, but I don't have the time to dig in further...

@waqadArshad
Copy link

@waqadArshad I just downgraded to flutter 3.0.5. Not a great solution, but I don't have the time to dig in further...

@JoshJuncker thanks a lot. I really appreciate this. I was stuck at this for quite a long time, thinking that there was something wrong with my code. I cannot really express how thankful I am. Thanks a lot.

@lielvan
Copy link

lielvan commented Nov 15, 2022

You need to add @pragma('vm:entry-point') to your callback function, otherwise flutter will treeshake it in production. See flutter downloader docs for an example.

Had a similar issue with Flutter 3.3.5 & Dart 2.18.2, can confirm this solved it. Thank you 👍

  flutter_uploader:
    dependency: "direct main"
    description:
      name: flutter_uploader
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.0-beta.4"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants