Skip to content

Regenerate Dart plugin registrant after a hot restart #76219

Closed

Description

@blasten

The Dart plugin registrant is generated once the app is initially compiled.
There's a case where a user may start a flutter run session, then change the pubspec.yaml in the middle, and then hot restart the app.

With the changes from #74469, these steps will yield into an error.

In the case the plugins were removed from pubpsec.yaml:

Error: Could not resolve the package 'url_launcher_linux' in 'package:url_launcher_linux/url_launcher_linux.dart'.
Error: Could not resolve the package 'url_launcher_macos' in 'package:url_launcher_macos/url_launcher_macos.dart'.
.dart_tool/flutter_build/generated_main.dart:9:8: Error: Not found: 'package:url_launcher_linux/url_launcher_linux.dart'
import 'package:url_launcher_linux/url_launcher_linux.dart';
       ^
.dart_tool/flutter_build/generated_main.dart:10:8: Error: Not found: 'package:url_launcher_macos/url_launcher_macos.dart'
import 'package:url_launcher_macos/url_launcher_macos.dart';
       ^
.dart_tool/flutter_build/generated_main.dart:15:7: Error: Getter not found: 'UrlLauncherPlugin'.
      UrlLauncherPlugin.registerWith();
      ^^^^^^^^^^^^^^^^^
.dart_tool/flutter_build/generated_main.dart:17:7: Error: Getter not found: 'UrlLauncherPlugin'.
      UrlLauncherPlugin.registerWith();
      ^^^^^^^^^^^^^^^^^
Performing hot restart...                                              ⣾Error: Could not resolve the package 'url_launcher_linux' in 'package:url_launcher_linux/url_launcher_linux.dart'.
Error: Could not resolve the package 'url_launcher_macos' in 'package:url_launcher_macos/url_launcher_macos.dart'.
.dart_tool/flutter_build/generated_main.dart:9:8: Error: Not found: 'package:url_launcher_linux/url_launcher_linux.dart'
import 'package:url_launcher_linux/url_launcher_linux.dart';
       ^
.dart_tool/flutter_build/generated_main.dart:10:8: Error: Not found: 'package:url_launcher_macos/url_launcher_macos.dart'
import 'package:url_launcher_macos/url_launcher_macos.dart';
       ^
.dart_tool/flutter_build/generated_main.dart:15:7: Error: Getter not found: 'UrlLauncherPlugin'.
      UrlLauncherPlugin.registerWith();
      ^^^^^^^^^^^^^^^^^
.dart_tool/flutter_build/generated_main.dart:17:7: Error: Getter not found: 'UrlLauncherPlugin'.
      UrlLauncherPlugin.registerWith();

Activity

  1. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Feb 17, 2021
  2. self-assigned this
    on Feb 17, 2021
  3. jonahwilliams commented on Feb 17, 2021

    @jonahwilliams
    Contributor

    Either hot reload or hot restart could require regeneration - but only if the pubspec.yaml has changed. See the localizations code for some examples of how to wire this up https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/resident_runner.dart#L912

  4. added
    P1High-priority issues at the top of the work list
    on Feb 17, 2021
  5. zanderso commented on Mar 5, 2021

    @zanderso
    Member

    @blasten The beta branch cut is coming up very soon. What is the status of this?

  6. blasten commented on Mar 6, 2021

    @blasten
    Author

    @cyanglaz offered help. Thanks! I will be OOO starting next week.

    From a very quick look, it would need to call this function from here (Hot restart) if the pubpsec.yaml has changed since last time it was invoked.

  7. removed their assignment
    on Mar 6, 2021
  8. cyanglaz commented on Mar 8, 2021

    @cyanglaz

    I'm confused about the expected result. Just want to confirm:

    If I remove some deps (say url_launcher), and do a hot reload/restart, I should see the error in the main description of this issue, correct?

    So what is the issue? Is the issue about error not showing?

  9. jonahwilliams commented on Mar 8, 2021

    @jonahwilliams
    Contributor

    If I remove some deps (say url_launcher), and do a hot reload/restart, I should see the error in the main description of this issue, correct?

    It should be possible to remove a plugin from the pubspec and hot reload or restart without a compilation error.

  10. cyanglaz commented on Mar 9, 2021

    @cyanglaz

    I just tried with removing url_launcher in the middle of an app session, and run a hot restart, it seems fine, no error is generated.

    Screen.Recording.2021-03-08.at.4.07.10.PM.mov
  11. jonahwilliams commented on Mar 9, 2021

    @jonahwilliams
    Contributor

    If you removed url_launcher from your pubspec yaml in an example app that was using url_launcher you should get a compilation error - did pub get run and remove url_launcher from the package_config.json? You would also need to remove the usage from the app itself.

  12. cyanglaz commented on Mar 9, 2021

    @cyanglaz

    I removed the url_launcher when the app is running, then hot restarted.
    The hot start did not run pub get, which leads to no error.

  13. jonahwilliams commented on Mar 9, 2021

    @jonahwilliams
    Contributor

    The tool doesn't run pub for you on hot restart/reload

  14. cyanglaz commented on Mar 9, 2021

    @cyanglaz

    talked to @blasten, I need to apply flutter-team-archive/plugins#3577 to reproduce the issue.

  15. jonahwilliams commented on May 4, 2021

    @jonahwilliams
    Contributor

    Fixed via #79669

  16. github-actions commented on Aug 2, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  17. locked as resolved and limited conversation to collaborators on Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listtoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions