checkAgpVersion method
Check the Android Gradle Plugin version in the root build.gradle
Implementation
Future<void> checkAgpVersion() async {
final buildGradlePath = FileSystemUtils.findRootBuildGradle(androidDir);
if (buildGradlePath == null) {
issues.add(
IssueModel(
filePath: path.join(androidDir, 'build.gradle'),
description: 'Root build.gradle file not found',
currentValue: 'Missing',
recommendedValue: 'Create the file with proper configuration',
isCritical: true,
),
);
return;
}
final content = await FileSystemUtils.readFile(buildGradlePath);
final RegExp agpVersionRegex = RegExp(
r"com\.android\.tools\.build:gradle:([0-9.]+)",
);
final match = agpVersionRegex.firstMatch(content);
if (match == null) {
issues.add(
IssueModel(
filePath: buildGradlePath,
description: 'Android Gradle Plugin version not found',
currentValue: 'Unknown',
recommendedValue: latestAgpVersion,
isCritical: true,
),
);
return;
}
final currentVersion = match.group(1) ?? '';
if (_isVersionLowerThan(currentVersion, latestAgpVersion)) {
issues.add(
IssueModel(
filePath: buildGradlePath,
description: 'Android Gradle Plugin version is outdated',
currentValue: currentVersion,
recommendedValue: latestAgpVersion,
),
);
}
}