build method
Executes the complete build process.
Orchestrates the entire build workflow including:
- Logging build configuration
- Running Flutter build command
- Moving output files to distribution directories
- Generating debug symbols (for Android release builds)
Returns the process exit code (0 indicates success).
The build process includes proper error handling and logging at each step to facilitate debugging build issues.
Implementation
Future<int> build() async {
// Display build configuration before starting
await printJob();
// Get processed arguments with variable substitution
final arguments = await this.arguments;
logger.logDebug.call(
"Starting build with flutter ${["build", ...arguments].join(" ")}",
);
// Start Flutter build process
final process = await Process.start(
"flutter",
["build", ...arguments],
runInShell: true,
includeParentEnvironment: true,
);
// Stream build output to logger
process.stdout.transform(utf8.decoder).listen(logger.logDebug);
process.stderr.transform(utf8.decoder).listen(logger.logErrorVerbose);
// Wait for build completion
final exitCode = await process.exitCode;
if (exitCode != 0) {
logger.logDebug.call("Build failed with exit code: $exitCode");
return exitCode;
}
// Move output files to distribution directory
final moveResult = await _moveOutputFiles();
if (moveResult != 0) return moveResult;
// Generate debug symbols for Android release builds
if ((this is android_arguments.Arguments)) {
if (buildMode == "release" &&
(this as android_arguments.Arguments).generateDebugSymbols) {
final zipResult = await _generateAndCopyZipSymbols();
if (zipResult != 0) return zipResult;
}
}
return exitCode;
}