Skip to content

fix: flutter_plugin has inconsistent names on the native classes #271

@erickzanardo

Description

@erickzanardo

Description

The plugins created by the CLI have wrong names on their native classes, which prevents to create and just starting using the generated code.

Steps To Reproduce

  1. Run very_good create -t flutter_plugin hello
  2. Enter on the app facing package and create an example app by flutter create example
  3. Run flutter pub get on the example app
  4. See error

Expected Behavior
The generated plugin should be generated in a working state

Additional Context

This are the inconsistency that I identified:

On Android

  • The plugin class is stored on the wrong folder, on the pubspec its package is com.example.verygoodcore.hello, but it is placed inside the src/main/kotlin/com/example/verygoodcore folder, which is missing one additional folder called hello.
  • The pluginClass on the pubspec is also different from the name of the class on the source file, on the pubspec is HelloAndroidPlatform while on the source it is HelloPlugin

On iOS

  • The podspec file is named hello.podspec and should be named hello_ios.podspec
  • The name attribute on the podspec file also is just hello and should be hello_ios
  • The imports on HelloPlugin.m are missing the _ios suffix on the folders and file.

This is how it looks when the plugin is generated:

#import "HelloPlugin.h"
#if __has_include(<hello/hello-Swift.h>)
#import <hello/hello-Swift.h>
#else
// Support project import fallback if the generated compatibility header
// is not copied when this plugin is created as a library.
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
#import "hello-Swift.h"

And changing to the following fixes:

#import "HelloPlugin.h"
#if __has_include(<hello_ios/hello_ios-Swift.h>)
#import <hello_ios/hello_ios-Swift.h>
#else
// Support project import fallback if the generated compatibility header
// is not copied when this plugin is created as a library.
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
#import "hello_ios-Swift.h"
  • The plugin class name is wrong on the plubspec, it is generated with HelloIosPlatform, but the class name is SwiftHelloPlugin,

On MacOs

  • Same issue with podspec error mentioned on the iOS
  • The pubspec is using the ios key on the flutter/plugin/platforms section, when it should be macos

Web seems to work flawless out of the box. I couldn't test on Linux/Windows.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions