findGradleFiles static method
Find build.gradle or build.gradle.kts for Android/Flutter projects
Implementation
static List<File> findGradleFiles(
String projectPath,
ProjectType projectType,
) {
final files = <File>[];
if (projectType == ProjectType.flutter) {
final paths = [
path.join(projectPath, 'android', 'app', 'build.gradle'),
path.join(projectPath, 'android', 'app', 'build.gradle.kts'),
path.join(projectPath, 'android', 'build.gradle'),
path.join(projectPath, 'android', 'build.gradle.kts'),
];
for (final p in paths) {
final file = File(p);
if (file.existsSync()) files.add(file);
}
} else if (projectType == ProjectType.android) {
final dir = Directory(projectPath);
final gradleFiles = dir.listSync(recursive: true).whereType<File>().where(
(f) {
return f.path.endsWith('build.gradle') ||
f.path.endsWith('build.gradle.kts');
},
);
files.addAll(gradleFiles);
}
return files;
}