Skip to content

Lesson 7 of 9 · 27m

Flavors, Signing, and Reproducible Release Builds

Configure environments and credentials deliberately so Android, iOS, web, and desktop artifacts are traceable, signable, and reproducible.

Shipping one Flutter codebase to four platform families is not one build command repeated four times. It is release engineering: environment separation, signing material, version coordination, artifact provenance, and rollback. The worst time to design this is the night before a store submission.

Flavors are environment boundaries

Use flavors or entrypoints to encode environment, not random runtime booleans. A common pattern is:

lib/main_dev.dart
lib/main_staging.dart
lib/main_prod.dart
Future<void> main() async {
  await bootstrap(
    AppConfig(
      environment: Environment.prod,
      apiBaseUrl: Uri.parse('https://api.sudosecurity.org'),
      enableVerboseLogs: false,
    ),
  );
}

Android also needs Gradle flavor wiring; iOS often uses schemes and configurations. Web and desktop do not share the same store constraints, but they still need environment separation. --dart-define is useful for non-secret configuration. It is not a secret store: compiled values are extractable from shipped artifacts.

flutter build apk --release --flavor prod -t lib/main_prod.dart   --dart-define=APP_ENV=prod   --dart-define=API_BASE_URL=https://api.sudosecurity.org

Android signing is asset custody

The upload key, keystore passwords, and Play app signing relationship determine whether you can update your own app. Do not keep the only copy of the keystore on a laptop. In modern Android projects, wire signing in android/app/build.gradle.kts or CI secret material:

signingConfigs {
    create("release") {
        storeFile = file(System.getenv("ANDROID_KEYSTORE_PATH") ?: "release.keystore")
        storePassword = System.getenv("ANDROID_KEYSTORE_PASSWORD")
        keyAlias = System.getenv("ANDROID_KEY_ALIAS")
        keyPassword = System.getenv("ANDROID_KEY_PASSWORD")
    }
}

Keep passwords in a CI secret manager, never in git. Prefer Play app signing so Google manages the app signing key while you manage upload keys.

iOS signing is a moving target

iOS adds certificates, provisioning profiles, bundle IDs, capabilities, and App Store Connect records. Flutter can build the archive, but Xcode and Apple infrastructure still matter:

flutter build ipa --release --export-method app-store

Use a dedicated CI machine identity or cloud signing service. Record which certificate and profile produced the artifact. When a build fails with a provisioning error, do not randomly regenerate everything; inspect bundle ID, capability entitlements, team ID, and expiration dates first.

Version codes are operational data

Flutter's pubspec.yaml version combines marketing version and build number:

version: 1.4.0+42

1.4.0 is user-visible; 42 is the build number. Android and iOS interpret pieces differently, and stores require monotonic upload ordering. Decide whether CI owns build numbers. Manual increments eventually collide. Web cache-busting and desktop update metadata may need the same version exposed differently.

Reproducibility means knowing what shipped

Record commit SHA, Flutter version, Dart version, build flags, environment, dependency lockfile state, and artifact hash. A release note that says only "bug fixes" is not provenance. Ideally CI emits an artifact manifest:

{
  "commit": "8f2e1d4",
  "flutter": "3.29.2",
  "target": "android-prod",
  "version": "1.4.0+42",
  "artifact_sha256": "b94d27b9934d3e08a52e52d7da7dabfade..."
}

When a user reports a crash, you should know exactly which binary they run and how to recreate it.

Field notes

  • Do not put production service-account keys in --dart-define; compile-time configuration is visible in the artifact.
  • Android app bundles are for Play distribution; APKs are still useful for direct testing but have different signing and installation behavior.
  • iOS debug symbols and dSYMs matter. Without symbolication, crash stacks become decoration.
  • Store review time is part of release engineering; do not design rollback that depends on instant approval.
  • If the same version behaves differently by platform, inspect build flags and generated environment configuration before blaming application logic.

Was this lesson helpful?

Sign in to rate