Use Gradle KTS in new Android app projects by default (2nd try) (#157195)

This PR resolves #151166

This PR relands #154061
This commit is contained in:
Bartek Pacia
2024-10-22 19:28:31 +02:00
committed by GitHub
parent 9edd1ae008
commit eb5ef69d6b
20 changed files with 162 additions and 131 deletions

View File

@@ -467,7 +467,19 @@ class AndroidProject extends FlutterProjectPlatform {
static final RegExp _androidNamespacePattern = RegExp('android {[\\S\\s]+namespace\\s*=?\\s*[\'"](.+)[\'"]');
static final RegExp _applicationIdPattern = RegExp('^\\s*applicationId\\s*=?\\s*[\'"](.*)[\'"]\\s*\$');
static final RegExp _imperativeKotlinPluginPattern = RegExp('^\\s*apply plugin\\:\\s+[\'"]kotlin-android[\'"]\\s*\$');
static final RegExp _declarativeKotlinPluginPattern = RegExp('^\\s*id\\s+[\'"]kotlin-android[\'"]\\s*\$');
/// Examples of strings that this regex matches:
/// - `id "kotlin-android"`
/// - `id("kotlin-android")`
/// - `id ( "kotlin-android" ) `
/// - `id "org.jetbrains.kotlin.android"`
/// - `id("org.jetbrains.kotlin.android")`
/// - `id ( "org.jetbrains.kotlin.android" )`
static final List<RegExp> _declarativeKotlinPluginPatterns = <RegExp>[
RegExp('^\\s*id\\s*\\(?\\s*[\'"]kotlin-android[\'"]\\s*\\)?\\s*\$'),
RegExp('^\\s*id\\s*\\(?\\s*[\'"]org.jetbrains.kotlin.android[\'"]\\s*\\)?\\s*\$'),
];
/// Pattern used to find the assignment of the "group" property in Gradle.
/// Expected example: `group "dev.flutter.plugin"`
@@ -563,7 +575,9 @@ class AndroidProject extends FlutterProjectPlatform {
/// True, if the app project is using Kotlin.
bool get isKotlin {
final bool imperativeMatch = firstMatchInFile(appGradleFile, _imperativeKotlinPluginPattern) != null;
final bool declarativeMatch = firstMatchInFile(appGradleFile, _declarativeKotlinPluginPattern) != null;
final bool declarativeMatch = _declarativeKotlinPluginPatterns.any((RegExp pattern) {
return (firstMatchInFile(appGradleFile, pattern) != null);
});
return imperativeMatch || declarativeMatch;
}