Skip to content

flutter pub get fails on Flutter plugins supporting only v2 Android Embedding API #66561

@hitman-codehq

Description

@hitman-codehq

This is a very specific bug that only occurs in certain circumstances.

You have a Flutter plugin that supports Android Embedding API v2 but not v1
You have deleted the "example" directory that is generated by the "flutter create --template=plugin" command
When executing "flutter pub get" you will always get the following output:

$ flutter pub get
Running "flutter pub get" in Embedding... 0,4s
The plugin Embedding requires your app to be migrated to the Android embedding v2. Follow the steps on
https://flutter.dev/go/android-project-migration and re-run this command.

Unfortunately, this message is incorrect and quite misleading.

I dug into the source code and it turns out that when pub get is running, it searches for the plugin implementation, which will be in a file something like:

android/src/main/kotlin/com/my_company/my_plugin/MyPlugin.kt

It loads the text for the plugin and scans it for the word "registerWith". If it finds it, it assumes that the plugin supports the Android Embedding v1 API. If not then it assumes that it only supports the v2 API.

Then it tries to look for the following file:

example/android/src/main/AndroidManifest.xml

It then checks in this file to see what the flutterEmbedding value is. If it is not "2" then it displays the message above about needing to migrate the app.

The problem is that if you have a plugin that does not contain the example directory and the AndroidManifest.xml file then you will always get the error above. But it cannot be fixed - you can't upgrade the app to the version 2 API because the app doesn't exist...

This was causing us problems in our CI system when we tried to run dartdoc to generate documentation. dartdoc executes "flutter pub get", which fails and then dartdoc bombs out.

The workaround was to put the keyword "registerWith" somewhere in the plugin's source code.

I have attached a zip file that contains an example that shows this problem. Simple unzip it, cd into the "Embedding" directory and type "dartdoc".

I would like to get involved with Flutter and volunteer to fix this bug myself. I have already extensively investigated it as you can see, so the main thing to do now is to decide the best way to implement the bug fix. Perhaps only check the AndroidManifext.xml file if the example directory exists?

Embedding.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: qualityA truly polished experiencefound in release: 1.20Found to occur in 1.20found in release: 1.22Found to occur in 1.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versiontoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions