Issue https://github.com/flutter/flutter/issues/140548 requests that Flutter tool start supporting Gradle KTS (that is settings.gradle.kts and build.gradle.kts files), in addition to settings.gradle and build.gradle which use Groovy.
PR https://github.com/flutter/flutter/pull/140744 implements this feature, but does not implement all checks, such as failing when e.g. neither build.gradle.kts and build.gradle exist.
We didn't do that in PR #140744 because we wanted to keep it lean, and that change caused test failures that would result in many out of scope changes.
/// Gets top-level Gradle build file.
/// See https://developer.android.com/build#top-level.
///
/// The file must exist and it must be written in either Groovy (build.gradle)
/// or Kotlin (build.gradle.kts).
File get hostAppGradleFile {
final File buildGroovy = hostAppGradleRoot.childFile('build.gradle');
final File buildKotlin = hostAppGradleRoot.childFile('build.gradle.kts');
if (buildGroovy.existsSync() && buildKotlin.existsSync()) {
throwToolExit('Both build.gradle and build.gradle.kts exist. Only once can be used.');
}
if (buildKotlin.existsSync()) {
return buildKotlin;
}
if (buildGroovy.existsSync()) {
return buildGroovy;
}
throwToolExit("Neither build.gradle nor build.gradle.kts exist. This is an error");
}
Summary
Issue https://github.com/flutter/flutter/issues/140548 requests that Flutter tool start supporting Gradle KTS (that is
settings.gradle.kts
andbuild.gradle.kts
files), in addition tosettings.gradle
andbuild.gradle
which use Groovy.PR https://github.com/flutter/flutter/pull/140744 implements this feature, but does not implement all checks, such as failing when e.g. neither
build.gradle.kts
andbuild.gradle
exist.We didn't do that in PR #140744 because we wanted to keep it lean, and that change caused test failures that would result in many out of scope changes.
Changes to be made
Example of code that should be added to
packages/flutter_tools/lib/src/project.dart
: