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

Missing calls to "registerWith()" in generated dart_plugin_registrant.dart #113720

Closed
miquelbeltran opened this issue Oct 19, 2022 · 3 comments
Closed

Comments

@miquelbeltran
Copy link
Member

miquelbeltran commented Oct 19, 2022

Steps to Reproduce

  1. Create a new Flutter project. e.g. flutter create my_example
  2. cd my_example
  3. Add connectivity_plus: flutter pub add connectivity_plus
  4. Add package_info_plus flutter pub add package_info_plus
  5. Run the project (on Linux) flutter run -d linux
  6. Open .dart_tool/flutter_build/dart_plugin_registrant.dart

At this point, the contents of the file look like this:

@pragma('vm:entry-point')
class _PluginRegistrant {

  @pragma('vm:entry-point')
  static void register() {
    if (Platform.isAndroid) {
    } else if (Platform.isIOS) {
    } else if (Platform.isLinux) {
      try {
        ConnectivityPlusLinuxPlugin.registerWith();
      } catch (err) {
        print(
          '`connectivity_plus` threw an error: $err. '
          'The app may not function as expected until you remove this plugin from pubspec.yaml'
        );
        rethrow;
      }

    } else if (Platform.isMacOS) {
    } else if (Platform.isWindows) {
      try {
        PackageInfoPlusWindowsPlugin.registerWith();
      } catch (err) {
        print(
          '`package_info_plus` threw an error: $err. '
          'The app may not function as expected until you remove this plugin from pubspec.yaml'
        );
        rethrow;
      }

    }
  }
}

We will observe two problems:

  • The call to PackageInfoPlusLinuxPlugin.registerWith() is missing.
  • The call to ConnectivityPlusWindowsPlugin.registerWith() is missing.

If we remove the connectivity_plus plugin: flutter pub remove connectivity_plus, and run the project again, the contents of the file are:

@pragma('vm:entry-point')
class _PluginRegistrant {

  @pragma('vm:entry-point')
  static void register() {
    if (Platform.isAndroid) {
    } else if (Platform.isIOS) {
    } else if (Platform.isLinux) {
      try {
        PackageInfoPlusLinuxPlugin.registerWith();
      } catch (err) {
        print(
          '`package_info_plus` threw an error: $err. '
          'The app may not function as expected until you remove this plugin from pubspec.yaml'
        );
        rethrow;
      }

    } else if (Platform.isMacOS) {
    } else if (Platform.isWindows) {
      try {
        PackageInfoPlusWindowsPlugin.registerWith();
      } catch (err) {
        print(
          '`package_info_plus` threw an error: $err. '
          'The app may not function as expected until you remove this plugin from pubspec.yaml'
        );
        rethrow;
      }

    }
  }
}

Both calls to PackageInfoPlusLinuxPlugin.registerWith(); and PackageInfoPlusWindowsPlugin.registerWith(); are there.

Expected results:

The dart_plugin_registrant.dart should contain all registerWith methods.

Actual results:

The dart_plugin_registrant.dart is missing calls to register plugins properly.

In case this helps, here are the links to the codebase of these two plugins, if you can help spot an implementation error in them that may cause these issues:

However, I am afraid this issue may be affecting other packages as well that have multiplatform implementations as dartPluginClass.

Relevant info: This issue started happening when we refactored the packages from a "Federated Plugin" architecture, and moved all platform implementations into a single package, leaving the platform interface implementation into a separated package. So it looks like that federated plugins are not affected by this, only plugins where all the implementation is contained in the same package.

Code sample Not needed
Logs
20:32:43  ~/tmp/my_example  flutter pub add connectivity_plus
Resolving dependencies...
+ args 2.3.1
  collection 1.16.0 (1.17.0 available)
+ connectivity_plus 3.0.0
+ connectivity_plus_platform_interface 1.2.2
+ dbus 0.7.8
+ ffi 2.0.1
+ flutter_web_plugins 0.0.0 from sdk flutter
+ nm 0.5.0
+ petitparser 5.0.0
+ plugin_platform_interface 2.1.3
  stack_trace 1.10.0 (1.11.0 available)
+ xml 6.1.0
Changed 10 dependencies!
 20:33:02  ~/tmp/my_example  flutter pub add package_info_plus                                 
Resolving dependencies...
  collection 1.16.0 (1.17.0 available)
+ http 0.13.5
+ http_parser 4.0.2
+ package_info_plus 3.0.0
+ package_info_plus_platform_interface 2.0.0
  stack_trace 1.10.0 (1.11.0 available)
+ typed_data 1.3.1
+ win32 3.0.1
Changed 6 dependencies!
 20:33:11  ~/tmp/my_example  flutter run -d linux
Running "flutter pub get" in my_example...                         333ms
Resolving dependencies...
  collection 1.16.0 (1.17.0 available)
  stack_trace 1.10.0 (1.11.0 available)
Got dependencies!
Launching lib/main.dart on Linux in debug mode...
Building Linux application...                                           
Syncing files to device Linux...                                    83ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

💪 Running with sound null safety 💪

An Observatory debugger and profiler on Linux is available at: http://127.0.0.1:39373/BufDbgL3mrA=/
The Flutter DevTools debugger and profiler on Linux is available at:
http://127.0.0.1:9100?uri=http://127.0.0.1:39373/BufDbgL3mrA=/
Lost connection to device.
 20:33:26  ~/tmp/my_example  flutter pub remove connectivity_plus
Resolving dependencies...
  collection 1.16.0 (1.17.0 available)
  stack_trace 1.10.0 (1.11.0 available)
These packages are no longer being depended on:
- args 2.3.1
- connectivity_plus 3.0.0
- connectivity_plus_platform_interface 1.2.2
- dbus 0.7.8
- nm 0.5.0
- petitparser 5.0.0
- xml 6.1.0
Changed 7 dependencies!
 20:34:57  ~/tmp/my_example  flutter run -d linux                
Launching lib/main.dart on Linux in debug mode...
Building Linux application...                                           
Syncing files to device Linux...                                   106ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

💪 Running with sound null safety 💪

An Observatory debugger and profiler on Linux is available at: http://127.0.0.1:43907/zskvVezH_Xk=/
The Flutter DevTools debugger and profiler on Linux is available at:
http://127.0.0.1:9100?uri=http://127.0.0.1:43907/zskvVezH_Xk=/


Analyze
 20:37:17  ~/tmp/my_example  flutter analyze
Running "flutter pub get" in my_example...                         326ms
Resolving dependencies...
  collection 1.16.0 (1.17.0 available)
  stack_trace 1.10.0 (1.11.0 available)
Got dependencies!
Analyzing my_example...                                                 
No issues found! (ran in 1.1s)

Flutter Doctor -v
 20:37:21  ~/tmp/my_example  flutter doctor -v
[✓] Flutter (Channel master, 3.5.0-8.0.pre.50, on Ubuntu 22.04.1 LTS 5.15.0-52-generic, locale en_US.UTF-8)
    • Flutter version 3.5.0-8.0.pre.50 on channel master at /home/miquel/dev/tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 97e018d8b3 (62 minutes ago), 2022-10-19 10:36:02 -0700
    • Engine revision 563b8e830c
    • Dart version 2.19.0 (build 2.19.0-317.0.dev)
    • DevTools version 2.18.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/miquel/Android/Sdk
    • Platform android-33, build-tools 30.0.3
    • Java binary at:
      /home/miquel/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 14.0.0-1ubuntu1
    • cmake version 3.22.1
    • ninja version 1.10.1
    • pkg-config version 0.29.2

[✓] Android Studio (version 2021.2)
    • Android Studio at /home/miquel/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/212.5712.43.2112.8815526
    • 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
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] Android Studio (version 2021.3)
    • Android Studio at /home/miquel/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738
    • 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
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2022.2)
    • IntelliJ at /home/miquel/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/222.4345.14
    • Flutter plugin version 70.2.5
    • Dart plugin version 222.4345.14

[✓] VS Code (version 1.66.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.40.0

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.40.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.1 LTS 5.15.0-52-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 106.0.5249.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Note: Same issue in Channel Stable.

Related issue reported in plus_plugins: fluttercommunity/plus_plugins#1270

@stuartmorgan
Copy link
Contributor

Does setting the minimum Flutter version for the packages to 2.11.0 resolve this? You actually shouldn't be getting register calls at all with your current constraints (see the description of #96610).

@miquelbeltran
Copy link
Member Author

Thanks @stuartmorgan ! Increasing the minimum Flutter version did the trick when I tested locally. I will release new packages with the fix asap.

@github-actions
Copy link

github-actions bot commented Nov 3, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants