TLDR : c_api is not appending at the end of the include inside generated_plugin_registant.cc file when using flutter command to add windows plugin to an existing project
I am trying to add a windows implementation for an existing plugin that I have created. I followed the documentation given by Flutter team here and I am facing an issue with the generated_plugin_registrant.cc file placed under example/windows/flutter.
This file should be including the .h of plugin(s) that i am using in the example app. But it does it wrong.
My plugin is called util_public_store. That's how the file is generated
//
// Generated file. Do not edit.
//
// clang-format off
#include "generated_plugin_registrant.h"
#include <util_public_store/util_public_store_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
UtilPublicStorePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UtilPublicStorePlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
and that's what is inside windows generated library on plugin side.
The generated file has a "c_api" happened at the end of its name but not in the generated_plugin_registrant. I have used this command to generate the plugin and the example that goes with it :
flutter create --template=plugin --platforms=windows .
When i tried to make it from scratch, with the hello plugin given in their documentation, it works well but not when I use it from an existing project.
I suppose that their is some kind of version conflict or someting like that because i have older windows plugins that don't have the "c_api".h file in the include repository and that used to work well.
If you have any informations or advice for me, I would be glad to hear them.
Thanks.
The pluginClass
entry for Windows in your pubspecs.yaml needs to match the function and file naming of the public header. For historical reasons the template needs to use the _c_api
suffix, so if you are using the template unmodified you need to add CApi
to what you added to your pubspec.yaml.
Alternatively you can rename the public header and entry point function, but then you'll need to rename other files since having two headers with the same name in the same project is problematic.