diff --git a/packages/flutter_tools/lib/src/plugins.dart b/packages/flutter_tools/lib/src/plugins.dart index ee4edbdcdfb..89aafcd7c46 100644 --- a/packages/flutter_tools/lib/src/plugins.dart +++ b/packages/flutter_tools/lib/src/plugins.dart @@ -213,6 +213,14 @@ class Plugin { return [errorMessage]; } + if (!usesOldPluginFormat && !usesNewPluginFormat) { + const String errorMessage = + 'Cannot find the `flutter.plugin.platforms` key in the `pubspec.yaml` file. ' + 'An instruction to format the `pubspec.yaml` can be found here: ' + 'https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms'; + return [errorMessage]; + } + if (usesNewPluginFormat) { if (yaml['platforms'] != null && yaml['platforms'] is! YamlMap) { const String errorMessage = 'flutter.plugin.platforms should be a map with the platform name as the key'; @@ -264,6 +272,7 @@ class Plugin { static List _validateLegacyYaml(YamlMap yaml) { final List errors = []; + if (yaml['androidPackage'] != null && yaml['androidPackage'] is! String) { errors.add('The "androidPackage" must either be null or a string.'); } diff --git a/packages/flutter_tools/test/general.shard/flutter_manifest_test.dart b/packages/flutter_tools/test/general.shard/flutter_manifest_test.dart index fb28e4dfe9d..bfc2d78f6fd 100644 --- a/packages/flutter_tools/test/general.shard/flutter_manifest_test.dart +++ b/packages/flutter_tools/test/general.shard/flutter_manifest_test.dart @@ -1017,6 +1017,28 @@ flutter: expect(logger.errorText, contains('flutter.plugin.platforms should be a map with the platform name as the key')); }); + + testWithoutContext('FlutterManifest validates plugin format not support.', () { + const String manifest = ''' +name: test +flutter: + plugin: + android: + package: com.example + pluginClass: SomeClass + ios: + pluginClass: SomeClass +'''; + final BufferLogger logger = BufferLogger.test(); + final FlutterManifest flutterManifest = FlutterManifest.createFromString( + manifest, + logger: logger, + ); + + expect(flutterManifest, null); + expect(logger.errorText, + contains('Cannot find the `flutter.plugin.platforms` key in the `pubspec.yaml` file. ')); + }); } Matcher matchesManifest({