executeBuild method
Validates the environment, configuration, and project, then executes the build.
Supports targets: 'apk', 'appbundle', 'ipa'.
Implementation
Future<BuildResultModel> executeBuild(
String target, {
String? flavor,
String? env,
List<String> additionalArgs = const [],
}) async {
final startTime = DateTime.now();
try {
await _validateProject();
await _validateConfiguration();
await _validateFlutterInstallation();
// Determine the actual flutter build command target based on input
String flutterTarget = target.toLowerCase();
if (flutterTarget == 'aab') {
flutterTarget = 'appbundle';
}
if (!['apk', 'appbundle', 'ipa'].contains(flutterTarget)) {
throw ReleaseManagerException('Unsupported build target: $target. Only apk, aab, and ipa are supported.');
}
final buildArgs = ['build', flutterTarget];
if (flavor != null && flavor.isNotEmpty) {
buildArgs.addAll(['--flavor', flavor]);
}
if (env != null && env.isNotEmpty) {
buildArgs.addAll(['--dart-define=ENV=$env']);
}
buildArgs.addAll(additionalArgs);
final sdkInfo = await _flutterSdkService.getSdkInfo();
final result = await _processService.run(sdkInfo.executablePath, buildArgs);
if (result.exitCode != 0) {
return BuildResultModel(
isSuccess: false,
target: target,
buildDuration: DateTime.now().difference(startTime),
errorMessage: 'Build failed with exit code ${result.exitCode}:\n${result.stderr}',
);
}
return BuildResultModel(
isSuccess: true,
target: target,
buildDuration: DateTime.now().difference(startTime),
);
} catch (e) {
return BuildResultModel(
isSuccess: false,
target: target,
buildDuration: DateTime.now().difference(startTime),
errorMessage: e.toString(),
);
}
}