Skip to content
Prev Previous commit
Next Next commit
fix
  • Loading branch information
okorohelijah committed Feb 12, 2026
commit 5778ee8632f25bcecea77f9c32490f94801b4703
13 changes: 10 additions & 3 deletions packages/flutter_tools/lib/src/plugins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,21 @@ bool _hasFlutterFrameworkDependency(File packageSwiftFile) {

try {
final String contents = packageSwiftFile.readAsStringSync();
final bool hasPackageDependency = contents.contains(

final List<String> uncommentedLines = contents
.split('\n')
.where((String line) => !line.trim().startsWith('//'))
.toList();
final String uncommentedContents = uncommentedLines.join('\n');
Comment thread
okorohelijah marked this conversation as resolved.
Outdated

final bool hasPackageDependency = uncommentedContents.contains(
RegExp(r'\.package\s*\(\s*name\s*:\s*"FlutterFramework"'),
);
final bool hasTargetDependency = contents.contains(
final bool hasTargetDependency = uncommentedContents.contains(
RegExp(r'\.product\s*\(\s*name\s*:\s*"FlutterFramework"'),
);

return hasPackageDependency || hasTargetDependency;
return hasPackageDependency && hasTargetDependency;
} on FileSystemException {
return false;
}
Expand Down
59 changes: 59 additions & 0 deletions packages/flutter_tools/test/general.shard/plugins_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,65 @@ let package = Package(
},
);

testWithoutContext('invalidates commented-out FlutterFramework dependency', () {
final plugin = Plugin(
name: 'test_plugin',
path: '/path/to/test_plugin/',
defaultPackagePlatforms: const <String, String>{},
pluginDartClassPlatforms: const <String, DartPluginClassAndFilePair>{},
platforms: const <String, PluginPlatform>{
IOSPlugin.kConfigKey: IOSPlugin(name: 'test_plugin', classPrefix: ''),
},
dependencies: <String>[],
isDirectDependency: true,
isDevDependency: false,
);

fs.directory('/path/to/test_plugin/ios/test_plugin').createSync(recursive: true);
fs.file('/path/to/test_plugin/ios/test_plugin/Package.swift').writeAsStringSync('''
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "test_plugin",
platforms: [
.iOS("13.0"),
],
products: [
.library(name: "test-plugin", targets: ["test_plugin"]),
],
dependencies: [
// .package(name: "FlutterFramework", path: "../FlutterFramework")
],
targets: [
.target(
name: "test_plugin",
dependencies: [
// .product(name: "FlutterFramework", package: "FlutterFramework")
]
),
]
)
''');

final SwiftPackageManagerPluginValidationResult result =
validatePluginSwiftPackageManagerSupport(
plugin,
fileSystem: fs,
platform: IOSPlugin.kConfigKey,
);

expect(result.hasPodspec, isFalse);
expect(result.hasPackageSwift, isTrue);
expect(result.hasFlutterFrameworkDependency, isFalse);
expect(result.isFullyCompatible, isFalse);
expect(result.validationMessages, hasLength(1));
expect(
result.validationMessages.first,
contains('is missing a dependency on FlutterFramework'),
);
});

testWithoutContext('detects FlutterFramework dependency with product dependency syntax', () {
final plugin = Plugin(
name: 'test_plugin',
Expand Down