Shahzad Akram approach is almost correct:
It's important to open your_plugin/example/android
first and then your_plugin
.
In reality you never open your plugin, you open the example android project and there you can access your plugin, it is like opening an project that uses your plugin, then you can access your plugin with all dependencies.
If you open the plugin itself, AS will never load the Flutter jar dependency, neither androidx (sometimes it loads, but probably from cache).
This also applies for federated plugins! Or any other design that implies different Dart workspaces for the same package.
Full step
AS: Stands for Android Studio.
- Close all AS windows.
- Open AS initial window.
- Click to open project.
- Select your base Dart workspace (the one that contains the
example
folder).
- If you are depeloping a federated plugin, click on the
<plugin-name>
folder, not <plugin-name>_platform_interface
or <plugin-name>_android
.
- If you are depeloping a "normal" plugin, no secret, just open the root project.
- Then right click on your
example
folder -> Flutter -> Open Android module in Android Studio -> This window.
- Very important: select the sidebar "Android" view. NOT "Packages", "Projects", "Project Source Files", or anything else.
- The sidebar will show will two modules:
app
which is from your example/android
project; and the <plugin-name>
module, which is your actual plugin, use this to develop your plugin.
You may noticed that you will not be able to open your plugin directly with the intellisense features, you must open your plugin from the example project to be able to see the auto-completion for Android and Flutter java classes working.
Also: avoid using a custom gradle that will copy from the flutter.jar
from the Flutter SDK files and copy into the standalone plugin module, it will crash when loading your plugin from an app because the classes will be duplicated (loaded from app gradle AND from your plugin gradle) -> This is not applicable if you know gradle enough to build a custom script for you to avoid this error.