Flutter (Dart / Hybrid)
Flutter projects compile down to native artifacts (AAB/APK on Android, IPA on iOS). The recommended industry architecture is a dual-tier Fastlane setup: native platform Fastfiles inside android/fastlane/ and ios/fastlane/, orchestrated by a root Fastfile.
flowchart TD
Root["Root Fastfile (flutter pub get, version extraction, notifications)"]
Root --> AndroidFF["android/fastlane/Fastfile (flutter build appbundle & supply)"]
Root --> IosFF["ios/fastlane/Fastfile (flutter build ipa & pilot)"]
Directory Architecture
my_flutter_app/βββ pubspec.yaml # Single source of truth for version + buildβββ android/β βββ app/build.gradle.ktsβ βββ fastlane/β βββ Appfileβ βββ Fastfile # Android native lanesβββ ios/β βββ Runner.xcworkspaceβ βββ fastlane/β βββ Appfileβ βββ Matchfileβ βββ Fastfile # iOS native lanesβββ fastlane/β βββ Fastfile # Unified root orchestratorβββ Gemfileβββ Gemfile.lock1. Extracting Version from pubspec.yaml
Instead of hardcoding build numbers, read the version directly from pubspec.yaml:
require 'yaml'
module FlutterVersionHelper def self.load_version(repo_root) pubspec = YAML.load_file(File.join(repo_root, 'pubspec.yaml')) version_line = pubspec['version'] # e.g. "1.2.0+42" version_name, build_number = version_line.split('+')
{ version_name: version_name, build_number: build_number.to_i } endend2. Compiling Flutter Binaries via Fastlane sh
Use Fastlaneβs sh action to trigger the Flutter toolchain before running upload actions:
Android Lane:
# android/fastlane/Fastfileplatform :android do lane :build_and_deploy do |options| repo_root = File.expand_path('../..', __dir__)
# 1. Compile AAB via Flutter CLI sh("flutter", "build", "appbundle", "--release", chdir: repo_root)
# 2. Locate generated AAB aab_path = File.join(repo_root, "build/app/outputs/bundle/release/app-release.aab")
# 3. Upload to Google Play upload_to_play_store( aab: aab_path, track: options[:track] || "internal" ) endendiOS Lane:
# ios/fastlane/Fastfileplatform :ios do lane :build_and_deploy do |options| repo_root = File.expand_path('../..', __dir__)
# 1. Sync certificates match(type: "appstore", readonly: is_ci)
# 2. Build IPA via Flutter CLI sh("flutter", "build", "ipa", "--release", "--export-options-plist=ios/ExportOptions.plist", chdir: repo_root)
# 3. Locate generated IPA ipa_path = Dir.glob(File.join(repo_root, "build/ios/ipa/*.ipa")).first
# 4. Upload to TestFlight upload_to_testflight( ipa: ipa_path, skip_waiting_for_build_processing: true ) endend3. Passing Flutter Flavors (--flavor)
When managing multiple environments (e.g. dev, staging, prod):
lane :build_flavor do |options| flavor = options[:flavor] || "staging" target = "lib/main_#{flavor}.dart"
sh("flutter", "build", "appbundle", "--flavor", flavor, "--target", target, "--release")end