flutter_build
Build Flutter applications for specific target platforms like Android, iOS, web, and desktop. Specify build mode and flavor to generate APK, AppBundle, IPA, or platform-specific binaries from your Flutter project directory.
Instructions
Build Flutter app for specific target platform
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | Yes | Working directory (Flutter project root) | |
| target | Yes | Build target platform | |
| buildMode | No | Build mode | |
| flavor | No | Build flavor |
Implementation Reference
- src/tools/flutter.ts:674-716 (handler)The handler function executes the flutter_build tool. It validates input using Zod schema, checks if the directory is a valid Flutter project, constructs the appropriate 'flutter build' command with target, mode, and flavor flags, runs the command with a 30-minute timeout, and returns structured results including output and duration.handler: async (args: any) => { const validation = FlutterBuildSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { cwd, target, buildMode = 'debug', flavor } = validation.data; // Validate that it's a Flutter project await validateFlutterProject(cwd); const flutter_args = ['build', target]; if (buildMode !== 'debug') { flutter_args.push(`--${buildMode}`); } if (flavor) { flutter_args.push('--flavor', flavor); } const result = await processExecutor.execute('flutter', flutter_args, { cwd, timeout: 1800000, // 30 minutes timeout for builds }); if (result.exitCode !== 0) { throw new Error(`Flutter build failed: ${result.stderr || result.stdout}`); } return { success: true, data: { target, buildMode, flavor, projectPath: cwd, output: result.stdout, duration: result.duration, exitCode: result.exitCode, }, }; }
- src/tools/flutter.ts:81-86 (schema)Zod validation schema defining the input parameters for flutter_build: required cwd and target (specific build targets), optional buildMode (defaults to 'debug') and flavor.const FlutterBuildSchema = z.object({ cwd: z.string().min(1), target: z.enum(['apk', 'appbundle', 'ipa', 'ios', 'android', 'web', 'windows', 'macos', 'linux']), buildMode: z.enum(['debug', 'profile', 'release']).default('debug'), flavor: z.string().optional(), });
- src/tools/flutter.ts:653-717 (registration)The tool registration in createFlutterTools function, setting the tool config with name, description, JSON inputSchema (mirroring Zod schema), and reference to the handler function.tools.set('flutter_build', { name: 'flutter_build', description: 'Build Flutter app for specific target platform', inputSchema: { type: 'object', properties: { cwd: { type: 'string', minLength: 1, description: 'Working directory (Flutter project root)' }, target: { type: 'string', enum: ['apk', 'appbundle', 'ipa', 'ios', 'android', 'web', 'windows', 'macos', 'linux'], description: 'Build target platform' }, buildMode: { type: 'string', enum: ['debug', 'profile', 'release'], description: 'Build mode' }, flavor: { type: 'string', description: 'Build flavor' } }, required: ['cwd', 'target'] }, handler: async (args: any) => { const validation = FlutterBuildSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { cwd, target, buildMode = 'debug', flavor } = validation.data; // Validate that it's a Flutter project await validateFlutterProject(cwd); const flutter_args = ['build', target]; if (buildMode !== 'debug') { flutter_args.push(`--${buildMode}`); } if (flavor) { flutter_args.push('--flavor', flavor); } const result = await processExecutor.execute('flutter', flutter_args, { cwd, timeout: 1800000, // 30 minutes timeout for builds }); if (result.exitCode !== 0) { throw new Error(`Flutter build failed: ${result.stderr || result.stdout}`); } return { success: true, data: { target, buildMode, flavor, projectPath: cwd, output: result.stdout, duration: result.duration, exitCode: result.exitCode, }, }; } });
- src/tools/flutter.ts:158-169 (helper)Helper function called by the handler to validate that the provided cwd is a valid Flutter project by checking existence of pubspec.yaml and presence of 'flutter:' section.const validateFlutterProject = async (cwd: string): Promise<void> => { const pubspecPath = path.join(cwd, 'pubspec.yaml'); try { await fs.access(pubspecPath); const pubspecContent = await fs.readFile(pubspecPath, 'utf8'); if (!pubspecContent.includes('flutter:')) { throw new Error(`Directory does not appear to be a Flutter project. No flutter section found in ${pubspecPath}`); } } catch { throw new Error(`pubspec.yaml not found. Flutter project must contain pubspec.yaml at: ${pubspecPath}`); } };