← Back to posts Cover image for Automating Flutter Release Workflows: Streamlining Versioning and App Icon Management

Automating Flutter Release Workflows: Streamlining Versioning and App Icon Management

· 5 min read
Weekly Digest

The Flutter news you actually need

No spam, ever. Unsubscribe in one click.

Chris
By Chris

Stop Doing Release Chores Manually

We’ve all been there. You’re ready to push a new release. You open pubspec.yaml, increment the version, then remember you need to bump the build number for the stores. You open your iOS project in Xcode to check the version there. Then you realize you promised a special holiday-themed app icon for this release, and you’re staring down the barrel of manually generating and placing 20+ different resolution PNGs across android/app/src/main/res/ and ios/Runner/Assets.xcassets/. It’s repetitive, error-prone, and frankly, a waste of your development time.

The good news? These are perfect tasks to automate. Let’s build a streamlined, reliable release workflow that handles versioning and icon management for you.

Automating Version and Build Number Bumps

The core of your app’s identity is in pubspec.yaml:

version: 1.2.3+45

The format is versionName+buildNumber. Manually editing this file, then ensuring it’s synchronized with your native iOS (Info.plist) and Android (build.gradle) projects, is where mistakes happen.

You can write a simple Dart script to handle this programmatically. Save this as scripts/bump_version.dart:

import 'dart:io';
import 'package:yaml/yaml.dart';

void main(List<String> args) {
  if (args.length < 2) {
    print('Usage: dart bump_version.dart <version> <build>');
    print('Example: dart bump_version.dart 1.2.4 46');
    exit(1);
  }

  final newVersion = args[0];
  final newBuild = args[1];
  final pubspecFile = File('pubspec.yaml');
  final pubspecContent = pubspecFile.readAsStringSync();
  final doc = loadYaml(pubspecContent) as YamlMap;

  // Update the version string in the YAML map
  doc['version'] = '$newVersion+$newBuild';

  // Write the updated YAML back to the file
  pubspecFile.writeAsStringSync(doc.toYaml());

  print('✅ Updated pubspec.yaml to version $newVersion+$newBuild');

  // Optional: Update iOS Info.plist (simplified example)
  final plistFile = File('ios/Runner/Info.plist');
  if (plistFile.existsSync()) {
    var plistContent = plistFile.readAsStringSync();
    // This is a naive string replacement; for production, use a proper plist parser.
    plistContent = plistContent.replaceAll(
      RegExp(r'<key>CFBundleShortVersionString</key>\s*<string>[\d\.]+</string>'),
      '<key>CFBundleShortVersionString</key>\n\t<string>$newVersion</string>',
    );
    plistContent = plistContent.replaceAll(
      RegExp(r'<key>CFBundleVersion</key>\s*<string>[\d\.]+</string>'),
      '<key>CFBundleVersion</key>\n\t<string>$newBuild</string>',
    );
    plistFile.writeAsStringSync(plistContent);
    print('✅ Updated iOS Info.plist');
  }
}

Run it with dart scripts/bump_version.dart 1.2.4 46. This is a foundational example. For a robust solution, you’d want to use a proper YAML emitter to preserve formatting and a real PLIST/XML parser for the native files.

Common Mistake: Forgetting that iOS App Store Connect now requires the build number (CFBundleVersion) to be unique for every upload, not just the version name. Automating this ensures you never accidentally re-use a build number.

Dynamic App Icon Management

Manually swapping app icons for seasonal campaigns or A/B testing is a multi-platform nightmare. The key is to define your icon sets as Flutter assets and use a build-time generator to copy the correct set into the native directories.

First, organize your icons in your project. For example, create a directory assets/app_icons/christmas/ containing your primary icon file (e.g., icon.png) and an adaptive_icon.png for Android.

You can then use a script or a dedicated package in your pubspec.yaml to process them. Here’s a conceptual Dart script that could be part of your CI/CD pipeline:

// scripts/set_icon.dart - Simplified concept
import 'dart:io';

void main(List<String> args) {
  if (args.isEmpty) {
    print('Specify icon set name, e.g., "christmas" or "default"');
    exit(1);
  }
  final iconSet = args[0];
  final sourceDir = Directory('assets/app_icons/$iconSet');

  if (!sourceDir.existsSync()) {
    print('❌ Icon set "$iconSet" not found.');
    exit(1);
  }

  // In reality, here you would:
  // 1. Use the `image` package to resize `icon.png` to all required resolutions.
  // 2. Copy the resized images to `android/app/src/main/res/mipmap-*/`.
  // 3. For iOS, copy the images into the `Assets.xcassets/AppIcon.appiconset` directory.
  // 4. For Android, you might need to generate/update an `activity-alias` in AndroidManifest.xml.
  // 5. For iOS, you would need to update the `CFBundleAlternateIcons` key in Info.plist.

  print('⚠️  Icon set "$iconSet" processing logic would run here.');
  print('For a full solution, consider a dedicated package or more complex script.');
}

The real complexity lies in the native platform integration—editing AndroidManifest.xml and Info.plist correctly. This is why many developers use community-maintained tools that abstract this complexity.

Pro Tip: If you use a package like flutter_launcher_icons, you can achieve this by having multiple configuration files (e.g., flutter_launcher_icons-christmas.yaml) and running the command with the --flavor or specific config file in your build script.

Putting It All Together in CI/CD

The power of automation shines in your CI/CD pipeline. Here’s a simplified GitHub Actions workflow snippet that ties it together:

# .github/workflows/release.yml
name: Release Build

on:
  push:
    tags:
      - 'v*'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Flutter
        uses: subosito/flutter-action@v2

      - name: Extract Tag Version
        id: tag
        run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

      - name: Bump Version and Build Number
        run: |
          # Calculate a build number from the CI run number
          BUILD_NUMBER=${{ github.run_number }}
          dart scripts/bump_version.dart ${{ steps.tag.outputs.VERSION }} $BUILD_NUMBER

      - name: Set Holiday Icon (if December)
        run: |
          if [ $(date +"%m") == "12" ]; then
            dart scripts/set_icon.dart "holiday"
          fi

      - name: Build APK and IPA
        run: flutter build apk --release && flutter build ipa --release

This workflow automatically versions your app based on the git tag, uses the CI run number for a unique build number, and even swaps in a holiday icon set for December releases.

By automating these steps, you eliminate manual errors, save significant time, and create a reproducible, audit-friendly release process. Start with a simple version bump script, then gradually add icon automation. Your future self, preparing the next release, will thank you.

This blog is produced with the assistance of AI by a human editor. Learn more

Related Posts

Cover image for Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Developers frequently struggle with persistent storage in Flutter, especially when dealing with OS-level backups and app reinstalls. This post will clarify the nuances of different storage solutions like `SharedPreferences`, `path_provider`, and `flutter_secure_storage`, focusing on how to correctly manage data lifetimes (per-install vs. per-user) and avoid issues like device IDs migrating to new phones or data being unexpectedly backed up.

Cover image for Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Flutter's `ImageFiltered` can cause significant lag when blurring large or frequently changing content like text. This post will explain the performance bottlenecks, provide solutions like caching blurred outputs with `RepaintBoundary` or `SnapshotWidget`, and offer practical tips to ensure smooth UI effects without sacrificing frame rates.