Simplifying CI/CD for Flutter Apps with Codemagic

Flutter

CI/CD

Engineering

Summary

This article examines Codemagic’s features that streamline CI/CD for mobile app development, particularly with Flutter. Codemagic supports multiple platforms and integrates with GitHub, GitLab, Bitbucket, and Azure DevOps for continuous deployment. The tool includes a hosted infrastructure, a user-friendly workflow editor, and flexible `codemagic.yaml` configurations. Guidelines for setting up and creating these configurations are also provided.

Key insights:
  • Unified CI/CD Solution for Multi-Platform Development: Codemagic enables development across iOS, Android, web, and desktop from a single interface, removing the need for local setup and simplifying multi-platform builds.

  • Integration with Major Version Control Systems: Codemagic seamlessly connects with GitHub, GitLab, Bitbucket, and Azure DevOps, automating CI/CD pipelines and post-push processes for efficient code management.

  • Flexibility with `codemagic.yaml` Configurations: Teams can customize their CI/CD workflows using codemagic.yaml for different build, test, and deployment configurations, making it adaptable to various project needs.

  • Streamlined Flutter-Specific Workflows: Codemagic offers a dedicated workflow editor for Flutter, making setup straightforward and reducing the complexity of building, testing, and deploying Flutter apps.

  • Automated Code Signing for iOS and Android: Codemagic integrates with the Apple Developer Portal for automated code signing on iOS and provides secure configurations for Android code signing, simplifying app releases.

  • Comprehensive Infrastructure and Setup Options: Codemagic’s hosted infrastructure includes distinct machine configurations, supporting Windows, Linux, and macOS for different build types and testing requirements.

  • Enhanced Testing and Deployment Flexibility: Codemagic provides automated testing, platform-specific builds, and artifact management, with support for Slack and email notifications for build updates.

  • Scalable Pricing Model for Teams of All Sizes: Codemagic’s pricing structure offers usage-based and unlimited plans, making it accessible for startups and scalable for larger teams needing parallel builds.

  • Security Compliance and Third-Party Integrations: Codemagic supports secure data handling, adhering to SOC 2, ISO 27001, GDPR, and CCPA standards, and integrates with third-party services for team collaboration.

  • Detailed Build and Deployment Guides for Multiple Platforms: Codemagic provides platform-specific instructions, including automated versioning, code signing, and testing setups, making it a valuable CI/CD tool for mobile development teams.

Introduction

Mobile development teams may expedite the testing, development, and release of mobile applications with Codemagic, an innovative Continuous Integration and Continuous Deployment (CI/CD) solution. Codemagic seamlessly integrates with well-known version control systems like GitHub, GitLab, Bitbucket, and Azure DevOps, enabling developers to push code changes while automating intricate post-push tasks. With support for native Android and iOS as well as frameworks like Flutter, React Native, and Unity, Codemagic is flexible and adaptable for a variety of mobile development needs. Together with Codemagic's strong automation features, this flexibility enables teams to improve workflows, cut down on tedious work, and expedite platform app delivery.

A fully hosted infrastructure that eliminates the need for local setups and a unified interface that streamlines cross-platform builds for desktop, web, and iOS are two of Codemagic's primary features. Teams may set up projects according to their needs thanks to Codemagic's various configuration options, which include a user-friendly user interface and sophisticated codemagic.yaml files for customized CI/CD procedures. Teams using Flutter will particularly benefit from Codemagic's dedicated workflow editor, which cuts down on setup time, and its smooth third-party integrations, which guarantee prompt notifications and problem solving. Codemagic enables mobile development teams to effectively bring high-caliber apps to market by emphasizing automation, usability, and platform flexibility. This article will outline Codemagic's functionality and offer instructions for incorporating it into Flutter projects.

What is Codemagic?

Mobile development teams can automate the testing, development, and release of mobile applications on all platforms with Codemagic, a potent CI/CD technology designed just for them. Because of Codemagic's smooth integration with popular version control systems like GitHub, GitLab, Bitbucket, and Azure DevOps, developers can push their work and rely on Codemagic to manage the intricate processes that come next. Codemagic is a flexible solution for a range of mobile development requirements because it supports several development frameworks, such as Flutter, React Native, Unity, and native Android and iOS. 

Key Features of Codemagic

1. Overview

Codemagic provides an extensive feature set to optimize workflows for mobile development. The ability to create apps for all platforms—iOS, Android, web, and desktop—using a single interface, which streamlines the development and deployment process, is one of its most notable features. Additionally, Codemagic offers a completely hosted and managed infrastructure that eliminates the need for local setups by giving development teams immediate access to a variety of hardware and software configurations. The time needed to deploy new app versions is greatly decreased by Codemagic's build automation tools, which let teams manage time-consuming, repetitive operations like code signing, uploading new app versions, and creating changelogs.

2. Ease of Use and Flexibility

Flexibility and usability were key considerations in the creation of Codemagic. Its user-friendly interface and codemagic.yaml configuration option give teams control over processes and allow them to customize CI/CD pipelines to meet their unique needs. Even people who are not familiar with CI/CD can use the tool because of its simple setup process and free onboarding help. Codemagic's customized workflow editor is especially helpful for teams working on Flutter projects, since it streamlines intricate setup procedures and lowers the learning curve.

3. First-Class Support for iOS Development

For iOS developers, who frequently have difficulties with code signing, Codemagic's interaction with the Apple Developer Portal is a significant benefit. Developers can release apps to the App Store more quickly thanks to this integration, which makes it easier to manage code-signing identities and certificates. Additionally, Codemagic makes testing on iOS emulators and devices easier, guaranteeing that iOS apps fulfill quality requirements prior to release. Because of these characteristics, Codemagic is a well-liked option for mobile teams who value dependable iOS workflows.

4. Seamless Integration with Third-Party Services

Codemagic readily integrates with the services and tools used by mobile development teams, such as well-known project management and messaging apps like Slack. With the help of this connection, teams can monitor CI/CD workflows and promptly resolve issues by receiving instant notifications and feedback for every build. Additionally, Codemagic facilitates automated testing and deployment, guaranteeing that apps undergo thorough testing prior to being made available to customers. Sensitive data is managed responsibly thanks to its safe and compliant infrastructure, which also complies with SOC 2, ISO 27001, GDPR, and CCPA standards.

5. Transparent Pricing and Scalability

With a choice between usage-based and unlimited plans, Codemagic provides various pricing options to meet the needs of expanding teams. Teams can speed up development cycles by adding more parallel builds as they grow. Because of its scalability, Codemagic may be used by teams of any size, from startups to major corporations. Budget management is also made easier by the predictable price system, which makes expenses clear as usage rises.

6. Why Choose Codemagic for CI/CD?

Codemagic is a useful solution for mobile development teams since it streamlines CI/CD, offers broad platform compatibility, and automates necessary operations for quicker app release. Codemagic simplifies processes with its user-friendly interface, extensive platform integration, and support for numerous frameworks, freeing up developers to concentrate on creating apps of the highest caliber. Codemagic is a dependable solution for teams wishing to improve their CI/CD procedures because of its secure infrastructure, dedicated iOS support, and versatile configuration options.

Setting up a Codemagic Flutter Project

Using Codemagic to build Flutter apps gives developers a simplified way to set up, create, and test their apps on a variety of platforms, including Windows, Linux, macOS, iOS, Android, and the web. This section offers a brief overview of Codemagic's workflow editor and platform setup options:

1. Workflow Editor

You can choose the platforms, build machine types, and other important parameters for your Flutter build environment using the Codemagic Workflow Editor. The editor allows you to create processes that solely test, create numerous targets in a single workflow, and distribute artifacts across several platforms. With support for Android, iOS, macOS, Linux, Windows, and the web, Codemagic is a versatile solution that can be used for a wide range of deployment requirements..

2. Basic Configuration

In Codemagic, you choose the platforms to build on first, followed by the sort of build machine needed for each platform. While macOS and Linux require distinct procedures on different machine instances, Android, iOS, and web apps can be developed in a single workflow. Keep in mind that some machine instances might only be accessible if billing is enabled. The availability matrix offers choices for developing web apps on Linux, macOS, or Windows, iOS apps on macOS, Android, and Windows apps on Windows computers.

2.1 Building Android Apps

The Flutter version, build mode (Debug, Release, or Profile), and extra arguments like build versioning or logging may all be specified for Android builds using Codemagic. Android code signing and choosing an output format (APK or App Bundle) are necessary when developing for release. App Bundles dynamically generate APKs specific to user devices and are suggested for publication on Google Play. If necessary, Codemagic can integrate Google's app signing service and automate publishing and signing to Google Play.

2.2 Building iOS Apps

Codemagic offers build mode, custom arguments, and settings for Flutter, Xcode, and Cocoapods versions for iOS builds. Making signed.ipa files for distribution in the App Store is made easier using the suggested command flutter build ipa. Release builds require code signing, and Codemagic facilitates the complete publishing and signing process for a seamless App Store upload.

2.3 Building Web Apps

If a web folder is included in a Flutter web project, Codemagic will automatically recognize it. The preferred Flutter version, build mode, and other parameters can be set up for web builds. After a successful build, Codemagic creates a .zip file containing the build directory, which can be downloaded or published using custom scripts to Codemagic Static Pages or other hosting websites.

2.4 Building macOS Apps

Codemagic recognizes Flutter projects that have a macOS folder, enabling builds on a macOS computer. In addition to other configurations, the build setup offers options for versions of Xcode, Cocoapods, and Flutter. The result is a ready-to-distribute .zip archive of the application file. Code signing creates a .pkg file for submission when building for the App Store.

2.5 Building Linux Apps

Flutter projects with a linux subdirectory can use Linux builds. Additional parameters, build mode, and Flutter versions can be specified via Codemagic. When a build is finished, a downloadable zip file is produced. Snap packages, which need a snapcraft.yaml file in the repository, can also be built by Linux users. Snap setup is handled by Codemagic, which enables local installation with the --dangerous flag or publishing to the Snap Store.

2.6 Building Windows Apps

With a windows folder, Codemagic can identify Flutter Windows projects and provide build options like as mode selection, version specification, and custom arguments. A .zip file containing the Windows executable is produced by Codemagic. Codemagic utilizes Flutter's msix package for MSIX packaging, an advanced Windows app format for the Microsoft Store, which necessitates setting within the app's pubspec.yaml file.

2.7 Running Tests Only

Codemagic offers a "Run tests only" mode for processes that are exclusively concerned with testing. This process bypasses the final app development and allows builds up to the testing stage. Automating test processes in response to pull requests or frequent code changes is made easier with this capability. Email or Slack integration can be used to receive notifications when a test is successful or unsuccessful.

2.8 Multiple Flutter Projects in One Repository

Codemagic can manage several Flutter projects in a single repository (monorepos) by identifying the pubspec.yaml file for each project. Codemagic chooses the project with the most suitable platforms for the first build. If directory paths change or new projects are created, you can manually modify project paths in the Workflow Editor.

Building and Publishing a Flutter App with Codemagic Using `codemagic.yaml`

Setting up a codemagic.yaml configuration file to specify build, test, and publishing routines is necessary when establishing a CI/CD pipeline for your Flutter application on Codemagic. This section ensures an effective deployment process by covering every stage of setting up this file, from code signing and publishing to repository integration:

1. Adding Your Flutter App to Codemagic

The first step is to log into Codemagic and add your Flutter app:

  • Go to the Applications page and click Add application.

  • Select the appropriate team if multiple teams exist.

  • Connect your app's source code repository. Select the project type and finalize by clicking Finish: Add application.

2. Creating `codemagic.yaml`

The codemagic.yaml file, placed in the root directory of the project, configures builds, tests, and publishing tasks. Below is the minimal setup:

workflows:
 sample-workflow:
   name: Codemagic Sample Workflow
   max_build_duration: 120
   instance_type

This file can contain multiple workflows, allowing to configure specific workflows for Android and iOS. Here is how to add separate workflows:

workflows:
 android-workflow:
   name: Android Workflow
 ios-workflow:
   name

3. Setting the Flutter Version

Flutter version should be defined in the environment to ensure consistency in the build process. It is possible to specify stable, beta, or master channels, or a specific version.

workflows:
 sample-workflow:
   environment:
     flutter

4. Code Signing for Android

For Android apps, create a keystore with the following command allows to sign your release builds:

keytool -genkey -v -keystore codemagic.keystore -storetype JKS \
       -keyalg RSA -keysize 2048 -validity 10000 -alias

Next, this keystore should be uploaded in Codemagic under Code signing identities. Next, reference the keystore in codemagic.yaml:

workflows:
 android-workflow:
   environment:
     android_signing

In android/app/build.gradle,  the signing configuration should be modified as follows:

signingConfigs {
   release {
     if (System.getenv()["CI"]) {
       storeFile file(System.getenv()["CM_KEYSTORE_PATH"])
       storePassword System.getenv()["CM_KEYSTORE_PASSWORD"]
       keyAlias System.getenv()["CM_KEY_ALIAS"]
       keyPassword System.getenv()["CM_KEY_PASSWORD"]
     }
   }
 }

5. Build and Test Scripts

These scripts should be added to build your Flutter app and set up the build environment:

workflows:
 android-workflow:
   scripts:
     - name: Set up local.properties
       script: |
         echo "flutter.sdk=$HOME/programs/flutter" > "$CM_BUILD_DIR/android/local.properties"
     - name: Get Flutter packages
       script: |
         flutter packages pub get
     - name: Build AAB with Flutter
       script: |
         flutter build appbundle --release
   artifacts

6. Automated Build Versioning

To meet app store requirements, the version number should be incremented with each build. Codemagic provides tools to retrieve the latest version from Google Play, increment it, and pass it as an argument:

workflows:
 android-workflow:
   environment:
     groups:
       - google_play
     vars:
       PACKAGE_NAME: "io.codemagic.fluttersample"
       GOOGLE_PLAY_TRACK: alpha
   scripts:
     - name: Increment Build Number
       script: |
         BUILD_NUMBER=$(($(google-play get-latest-build-number --package-name "$PACKAGE_NAME" --tracks="$GOOGLE_PLAY_TRACK") + 1))
         flutter build appbundle --release \
           --build-name=1.0.$BUILD_NUMBER \
           --build-number=$BUILD_NUMBER

7. Publishing the App

Codemagic allows automated publishing options (e.g. Google Play and App Store). For Google Play, set up a service account, credentials should be uploaded as a secure environment variable (GCLOUD_SERVICE_ACCOUNT_CREDENTIALS), and should be added in the codemagic.yaml file:

workflows:
 android-workflow:
   publishing:
     google_play:
       credentials: $GCLOUD_SERVICE_ACCOUNT_CREDENTIALS
       track: $GOOGLE_PLAY_TRACK
       submit_as_draft: true

8. Email Notifications

Email notifications should be configured to receive updates on build success or failure:

publishing:
 email:
   recipients:
     - user@example.com
   notify:
     success: true
     failure: false

9. Final `codemagic.yaml` Example

The completed file will look like this:

workflows:
 android-workflow:
   name: Android Workflow
   max_build_duration: 120
   environment:
     android_signing:
       - keystore_reference
     groups:
       - google_play
     vars:
       PACKAGE_NAME: "io.codemagic.fluttersample"
       GOOGLE_PLAY_TRACK: alpha
     flutter: stable
   scripts:
     - name: Set up local.properties
       script: |
         echo "flutter.sdk=$HOME/programs/flutter" > "$CM_BUILD_DIR/android/local.properties"
     - name: Get Flutter packages
       script: |
         flutter packages pub get
     - name: Build AAB with Flutter
       script: |
         BUILD_NUMBER=$(($(google-play get-latest-build-number --package-name "$PACKAGE_NAME" --tracks="$GOOGLE_PLAY_TRACK") + 1))
         flutter build appbundle --release \
           --build-name=1.0.$BUILD_NUMBER \
           --build-number=$BUILD_NUMBER
   artifacts:
     - build/**/outputs/**/*.aab
     - build/**/outputs/**/mapping.txt
   publishing:
     email:
       recipients:
         - user@example.com
       notify:
         success: true
         failure: false
     google_play:
       credentials: $GCLOUD_SERVICE_ACCOUNT_CREDENTIALS
       track: $GOOGLE_PLAY_TRACK
       submit_as_draft: true

This configuration enables automated builds, tests, code signing, versioning, and publishing, which streamlizes Flutter app's deployment on Codemagic.

Conclusion

To sum up, Codemagic is a strong CI/CD solution that is especially appropriate for mobile development teams that deal with a variety of frameworks, including native Android and iOS, Flutter, and React Native. Developers can easily automate complex operations with its robust feature set, which includes support for all major platforms, fully hosted infrastructure, easy third-party interfaces, and simplified code signing for iOS. Codemagic's user-friendly UI and codemagic.yaml settings provide flexibility, allowing teams to tailor workflows to their requirements and concentrate on producing high-caliber apps more quickly.

Codemagic is a vital tool for any team looking to improve the effectiveness of mobile app deployment because it supports platform-specific builds, testing, and publishing choices. Codemagic supports teams of all sizes, from startups to major corporations, with options for automated testing, flexible pricing, and scalable infrastructure. Ultimately, Codemagic offers mobile development teams a dependable and all-inclusive solution for continuous integration and delivery by streamlining and speeding up the CI/CD pipeline.

References

“Codemagic - CI/CD for Android, IOS, Flutter and React Native Projects.” Codemagic, codemagic.io/start/.

“Codemagic Documentation.” Codemagic.io, 2024, docs.codemagic.io/?_gl=1.

Other Insights

Got an app?

We build and deliver stunning mobile products that scale

Got an app?

We build and deliver stunning mobile products that scale

Got an app?

We build and deliver stunning mobile products that scale

Got an app?

We build and deliver stunning mobile products that scale

Got an app?

We build and deliver stunning mobile products that scale

Our mission is to harness the power of technology to make this world a better place. We provide thoughtful software solutions and consultancy that enhance growth and productivity.

The Jacx Office: 16-120

2807 Jackson Ave

Queens NY 11101, United States

Book an onsite meeting or request a services?

© Walturn LLC • All Rights Reserved 2024

Our mission is to harness the power of technology to make this world a better place. We provide thoughtful software solutions and consultancy that enhance growth and productivity.

The Jacx Office: 16-120

2807 Jackson Ave

Queens NY 11101, United States

Book an onsite meeting or request a services?

© Walturn LLC • All Rights Reserved 2024

Our mission is to harness the power of technology to make this world a better place. We provide thoughtful software solutions and consultancy that enhance growth and productivity.

The Jacx Office: 16-120

2807 Jackson Ave

Queens NY 11101, United States

Book an onsite meeting or request a services?

© Walturn LLC • All Rights Reserved 2024

Our mission is to harness the power of technology to make this world a better place. We provide thoughtful software solutions and consultancy that enhance growth and productivity.

The Jacx Office: 16-120

2807 Jackson Ave

Queens NY 11101, United States

Book an onsite meeting or request a services?

© Walturn LLC • All Rights Reserved 2024

Our mission is to harness the power of technology to make this world a better place. We provide thoughtful software solutions and consultancy that enhance growth and productivity.

The Jacx Office: 16-120

2807 Jackson Ave

Queens NY 11101, United States

Book an onsite meeting or request a services?

© Walturn LLC • All Rights Reserved 2024