Menu

Build Configurations

Relevant source files

This document details the build configuration system in the Flutter Mobile Project Template. It covers how different environment flavors are set up, how build parameters are managed across platforms, and how to build the application for various environments. For information about setting up the development environment, see IDE Setup.

1. Overview of Build Configuration System

The Flutter Mobile Project Template uses a robust build configuration system to manage different environments (development, staging, production) and platform-specific settings. This system enables developers to easily switch between environments during development and ensures consistent configuration across builds.

Sources: apps/app/android/app/build.gradle8-17

2. Environment Flavors

The project supports multiple environment flavors, each with its own configuration for app ID, name, and resources. These flavors typically include:

  • Development (dev): Used during active development
  • Staging (stg): Used for testing and QA
  • Production (prd): Used for release builds

2.1 Flavor-Specific Resources

Each flavor can have its own set of resources (icons, colors, etc.) which are copied to the appropriate locations during the build process.

Sources: apps/app/android/app/build.gradle19-26 apps/app/android/.gitignore15-20

3. Android Build Configuration

3.1 Gradle Configuration

The Android build configuration is primarily managed through Gradle. The project uses a system to extract parameters from the Flutter dart-defines and apply them to the Android build.

Sources: apps/app/android/app/build.gradle8-17 apps/app/android/app/build.gradle42-54

3.2 Key Android Configuration Parameters

ParameterDescriptionSource
appIdAndroidBase application IDdart-defines
appIdSuffixOptional suffix for variantsdart-defines
appNameDisplay name of the applicationdart-defines
flavorEnvironment flavor (dev/stg/prd)dart-defines

Sources: apps/app/android/app/build.gradle42-54

3.3 Resource Management

The build process copies resources from the flavor-specific directory to the main resources directory:

task copySources(type: Copy) {
    from "src/${dartDefines.flavor}/res"
    into 'src/main/res'
}

This ensures that the correct icons, colors, and other resources are included based on the environment.

Sources: apps/app/android/app/build.gradle19-26

4. iOS Build Configuration

The iOS configuration is managed through Xcode project settings and the Info.plist file. The build system uses the same dart-defines to configure iOS-specific parameters.

4.1 CocoaPods Integration

The project uses CocoaPods for managing iOS dependencies, as shown in the Podfile.lock:

Sources: apps/app/ios/Podfile.lock1-46

5. Accessing Build Configuration in Code

Build configuration parameters are accessible in the Flutter code through a BuildConfig class, which is injected using Riverpod providers. This allows for environment-specific behavior throughout the application.

Sources: apps/app/lib/router/router.dart28-51

6. Building for Different Environments

6.1 Command Line Build Examples

To build the application for different environments, use the Flutter build command with the appropriate dart-define parameters:

Development Build:

flutter build apk --dart-define=flavor=dev --dart-define=appName="App Dev" --dart-define=appIdAndroid=jp.co.yumemi.flutter_app.dev

Staging Build:

flutter build apk --dart-define=flavor=stg --dart-define=appName="App Staging" --dart-define=appIdAndroid=jp.co.yumemi.flutter_app.stg

Production Build:

flutter build apk --dart-define=flavor=prd --dart-define=appName="App" --dart-define=appIdAndroid=jp.co.yumemi.flutter_app

6.2 IDE Integration

The project includes configuration for both VS Code and IntelliJ IDEA, allowing developers to easily switch between build configurations within their IDE.

7. Application Manifestation of Build Configurations

The build configurations affect various aspects of the application at runtime:

Sources: apps/app/lib/ui/home_page.dart6-27 apps/app/lib/router/router.dart28-51

8. Secure Configuration Management

The build system is configured to ignore sensitive files such as keystores and key property files to ensure they aren't committed to the repository:

Sources: apps/app/android/.gitignore8-13


This documentation provides an overview of the build configuration system in the Flutter Mobile Project Template. By following the guidance here, developers can effectively work with different environments and build configurations.