Skip to content

Commit 3a97a38

Browse files
authored
Add support for type-safe plugin apply (#150958)
The Gradle Kotlin DSL also allows for type-safe application of the Flutter Gradle plugin, which is currently undetected by the CLI ```kotlin plugins { dev.flutter.`flutter-gradle-plugin` } ``` Please note that the added test case isn't ideal, since the example gradle isn't actually valid kotlin DSL, however the `kotlin host app language with Gradle Kotlin DSL` is identical Fixes #149859
1 parent 47e65e8 commit 3a97a38

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/flutter_tools/lib/src/project.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,9 @@ class AndroidProject extends FlutterProjectPlatform {
544544
// pluginManagement block of the settings.gradle file.
545545
// See https://docs.gradle.org/current/userguide/composite_builds.html#included_plugin_builds,
546546
// as well as the settings.gradle and build.gradle templates.
547-
final bool declarativeApply = line.contains('dev.flutter.flutter-gradle-plugin');
547+
final bool declarativeApply = line.contains(
548+
RegExp(r'dev\.flutter\.(?:(?:flutter-gradle-plugin)|(?:`flutter-gradle-plugin`))'),
549+
);
548550

549551
// This case allows for flutter run/build to work for modules. It does
550552
// not guarantee the Flutter Gradle Plugin is applied.

packages/flutter_tools/test/general.shard/project_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,28 @@ plugins {
805805
id "kotlin-android"
806806
id "dev.flutter.flutter-gradle-plugin"
807807
}
808+
''';
809+
});
810+
expect(project.android.isKotlin, isTrue);
811+
}, overrides: <Type, Generator>{
812+
FileSystem: () => fs,
813+
ProcessManager: () => FakeProcessManager.any(),
814+
XcodeProjectInterpreter: () => xcodeProjectInterpreter,
815+
FlutterProjectFactory: () => flutterProjectFactory,
816+
});
817+
818+
testUsingContext('kotlin host app language with Gradle Kotlin DSL and typesafe plugin id', () async {
819+
final FlutterProject project = await someProject();
820+
821+
addAndroidGradleFile(project.directory,
822+
kotlinDsl: true,
823+
gradleFileContent: () {
824+
return '''
825+
plugins {
826+
id "com.android.application"
827+
id "kotlin-android"
828+
dev.flutter.`flutter-gradle-plugin`
829+
}
808830
''';
809831
});
810832
expect(project.android.isKotlin, isTrue);

0 commit comments

Comments
 (0)