Blogs/Technology/Flutter CI/CD Workflow: A Simple Guide Using App Center
Flutter CI/CD Workflow: A Simple Guide Using App Center
May 21, 2024 • 13 Min Read
by Taha
Introduction to CI/CD for Flutter Development
In the fast-paced world of mobile app development, efficiency, reliability, and agility are key. Continuous integration and continuous delivery (CI/CD) has become an essential practice for Flutter developers to achieve these goals. CI/CD automates and streamlines the entire software delivery process, from the moment you commit code changes to making your app available to users on the App Store or Google Play (or for internal testing) on both Android and iOS devices. Let's explore the benefits of CI/CD for Flutter development and delve into how to leverage powerful tools like App Center to streamline your workflow.
What is CI/CD?
CI/CD stands for Continuous Integration and Continuous Delivery (or Deployment). It emphasizes frequent code integration, automated testing, and consistent software delivery to production environments. Here's a breakdown of the key components:
Continuous Integration: Developers regularly merge their code changes into a shared repository, enabling early detection of issues.
Continuous Delivery/Deployment: Automated processes build, test, and deploy code to various environments, ensuring a smooth flow towards production.
Benefits of CI/CD:
Accelerated Delivery: Automation accelerates software updates, reducing time-to-market and enabling quicker responses to market demands.
Early Detection of PR Issues: CI/CD swiftly spots PR issues like coding style violations and security flaws, minimizing the chance of them progressing to production. This proactive stance fortifies software quality and stability.
More Stable Production Setup: Continuous deployment guarantees consistent and controlled codebase deployment to production environments. This practice mitigates the risk of configuration drift and ensures stability across development, testing, and production environments.
Enhanced Collaboration: CI/CD promotes teamwork by encouraging frequent code integration and providing immediate feedback. This fosters transparency and shared ownership of the codebase among team members.
Iterative Development: CI/CD facilitates frequent releases of small changes. This allows for faster feedback loops, user input incorporation, and adaptation to evolving requirements.
CI/CD for Flutter Applications:
In the following sections, we'll explore implementing CI/CD pipelines for Flutter applications using App Center. We'll delve into best practices, practical tips, and real-world examples to help you master CI/CD for your Flutter projects.
What is Flutter?
Launched in 2018 by Google, Flutter has become a popular open-source framework (SDK) for building native-quality applications for mobile, web, and desktop platforms. Its growing adoption can be attributed to several key features that address common challenges in cross-platform development.
Key Features of Flutter:
Performance You Can Trust: Flutter apps are compiled directly to native machine code, ensuring exceptional performance, smooth animations, and a seamless user experience across different devices and platforms.
Expressive UI at Your Fingertips: Flutter boasts a rich collection of customizable UI components, widgets, and layouts. This empowers you to design stunning and interactive user interfaces that adhere to each platform's design guidelines.
Write Once, Deploy Everywhere: The beauty of Flutter lies in its ability to leverage a single codebase for deployment across various platforms (iOS, Android, Web, Desktop). This translates to reduced development time and minimized maintenance overhead.Witness the efficiency of Flutter with popular apps like Alibaba's Xianyu (e-commerce), Google Ads (mobile advertising), and The New York Times (news) reaching users on both mobile and web. Even desktops are benefiting from Flutter, with apps like Hamilton (the musical's companion app) and Stadia (Google's game streaming platform)
Native Feature Integration: Flutter integrates seamlessly with platform-specific features and APIs. Access device hardware, sensors, and native functionalities via platform channels. This approach provides an indirect access layer, but it ensures smooth integration without compromising performance or user experience.
App Center, developed by Microsoft, is a comprehensive platform designed to streamline the entire mobile app development lifecycle. It offers a suite of tools and services that empower developers to build, test, distribute, and monitor their applications more efficiently. With its cloud-based infrastructure and user-friendly interface, App Center streamlines the app development process, enabling teams to deliver high-quality apps to users with confidence.
Key Features of Microsoft App Center:
Continuous Integration (CI): Automate the build and testing of your mobile apps across various device configurations and platforms with App Center's CI service. Supporting popular frameworks and tools like Xamarin, React Native, and Flutter, App Center allows you to effortlessly set up CI pipelines to build, test, and validate your apps.
Continuous Delivery (CD): Streamline app update deployment and distribution with App Center's CD service. Distribute app builds to targeted audiences, monitor deployment status, and gather user feedback seamlessly by configuring release pipelines.
Automated Testing: App Center offers a range of testing services, including Real Device Testing (App Center Test Cloud), App distribution, crash reporting (Requires App Center SDK) and more to help you identify and address issues early in the development process. Run automated tests on real devices in the cloud, ensuring the quality and reliability of your apps across various platforms and device configurations.
Analytics and Monitoring: Gain valuable insights into user behavior, app crashes, and performance bottlenecks with App Center's comprehensive analytics and monitoring capabilities. Make data-driven decisions and prioritize improvements effectively by tracking app usage, performance, and stability in real-time.
By leveraging the strengths of Flutter for efficient cross-platform development and App Center's suite of tools for streamlined app management, you can significantly enhance your mobile app development workflow. If you're looking to hire Flutter developer experts, this combination ensures that your app is built with speed, quality, and reliability at the forefront. Stay tuned for the following sections, where we'll delve deeper into implementing CI/CD pipelines for Flutter applications using App Center!
Lets Dive-in! Setting Up App Center for Your Flutter Project
Till now, we explored the advantages of Flutter for cross-platform development and the comprehensive app management features of App Center. Now, let's bridge these powerful tools by setting up the App Center for your Flutter project. This will automate the build, test, and deployment processes, boosting your development workflow and productivity.
Here's a step-by-step guide to set up App Center for your Flutter project:
1: Create a New App in App Center
Head over to the App Center website and sign in using your Microsoft account.
Once logged in, locate the "Add new app" button (usually on the top right corner of the dashboard) and click on it.
Provide a name for your app, select the appropriate platform (likely "Android" or "iOS" depending on your target platform), and click on "Create" to finalize the app creation process. Note: We'll revisit App Center later to retrieve some key details for the next steps.
2: Configuring Your Flutter Android Project in App Center
Step 1: Adding a New App in App Center
Begin by launching the App Center dashboard and creating a new app. Here's what you'll need to provide:
Platform Selection: Choose the platform(s) your app targets. In this case, select "Android" or for cross-platform development, you can choose both "Android" and "iOS".
App Name: Assign a unique and descriptive name to your app for easy identification within the App Center.
Optional: App Owner: For improved organization within your team, you can assign an owner to the app. This can be helpful for managing access and responsibilities.
Partner with Us for Success
Experience seamless collaboration and exceptional results.
Step 2: Adding the App Center Script for the Android App
appcenter-post-clone.sh is a shell script file which allows you to tailor the App Center setup process for your Flutter project. This contains a series of commands that will be executed on your system. The exact actions it takes will depend on the specific content you paste into the script. By following the instructions and pasting the provided content, you'll be enabling App Center to interact with your Flutter project effectively
Navigate to your Flutter project's Android directory (flutterApp/android/app).
Create a new file named appcenter-post-clone.sh.
Paste the following content into the script:
Step 3: Updating Android .gitignore File
Locate the .gitignore file within your Android app directory (android/.gitignore).
Update the file to exclude the following entries (if not already excluded):
gradlew
gradlew.bat
.gitignore file is now going to look like this:
# gradle-wrapper.jar
/.gradle
/captures/
# /gradlew
# /gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
Step 4: Committing and Pushing Changes
Commit the newly created script appcenter-post-clone.sh and the updated .gitignore file to your source control system (e.g., GitHub, GitLab). And push your changes to the remote repository.
Step 5: Configuring Build in App Center
In your App Center dashboard and navigate to the app.
Click on the "Build" tab and connect your source control repository (e.g., GitHub).
Select the project, and choose the branch containing your Flutter code.
Click on the configuration icon to access the build settings.
If you encounter an error about missing Android projects, ensure you've completed Step 3 and your branch is up-to-date.
Under environment variables, add a new variable named JAVA_HOME and set its value to the path of your Java 11 x64 installation (e.g., JAVA_HOME: $(JAVA_HOME_11_X64)).
Look for the "Build scripts" section. If the appcenter-post-clone.sh script appears there, it signifies successful integration.
Choose your preferred build frequency: automatic builds on every push or manual triggers. Consider the free quota limitations (4 build hours per month) when selecting the frequency. Android and IOS builds usually consumes around 5 to 10 minutes each.
Step 6: Ensuring App Signing for Android
Within the build configuration settings, ensure you have a valid keystore JKS file uploaded. You'll also need the password, alias, and key password associated with the keystore.
Once everything is configured, click "Save & build" to initiate the build process.
After a successful build, navigate to the build details and select the latest generated version.
Click on "Distribute" to share the app with testers. You can choose to distribute the app Over-the-Air (OTA) to collaborators or download the APK directly.
Disclaimer: While App Center can be configured for automatic builds on every commit, we recommend a manual distribution approach to optimize build times. Frequent automatic builds for minor changes can consume unnecessary resources. By triggering builds and distributions only when needed, you can save valuable time and resources.
Here's a breakdown of the benefits of manual distribution in App Center:
Partner with Us for Success
Experience seamless collaboration and exceptional results.
Reduced Build Time and Costs: Automatic builds for every commit can add up, especially for larger projects. Manual distribution allows you to control when builds are triggered, saving time.
Focus on Meaningful Changes: By manually triggering builds, you ensure they occur after significant code changes, leading to more efficient testing and iteration cycles.
Resource Optimization: Manual distribution helps avoid unnecessary builds and distribution cycles, minimizing resource consumption on App Center's servers.
(Optional): Running Tests and Handling Builds
How to Run UI Tests on New Builds:
App Center doesn't directly integrate with Flutter for UI tests by default. However, you can achieve this by:
Writing your UI tests using a framework like Flutter Driver: This framework allows you to automate user interactions and test your app's UI.
Integrating this with our custom script: This script can trigger your UI tests and upload the results to App Center as it also generates our build.
Build Failures and Notifications:
App Center will notify you (via email by default) if a build fails. You can also configure additional notification channels, such as Slack alerts. To set up Slack alerts, you'll need to integrate the App Center with your Slack workspace using webhooks or any third party workflow integration.
3: Setting up your Flutter IOS Project in App Center
In the previous section, we walked through integrating the App Center for building and distributing your Flutter Android app. Now, let's navigate the steps to configure the App Center for your Flutter iOS project.
Step 1: Adding a New iOS App in App Center
Log in to your App Center dashboard.
Click the "Add new" button and select "Add new app" from the dropdown menu.
Provide a name and optional description for your app.
Under "Platform," choose "iOS" and under "Development technology," select "Swift/Objective-C."
Click on "Add new app" to finalize the creation of your iOS app in App Center.
Step 2: Connecting the Repository
Within your newly created iOS app in the App Center, locate the "Build" tab.
Click on the "Connect" button to link your source control repository (e.g., GitHub, GitLab).
Choose your preferred service, authenticate with your credentials, and select the project and branch containing your Flutter code.
Step 3: Adding App Center Script for iOS
Next, let's add another App Center script (appcenter-post-clone.sh) in the iOS directory (flutterApp/ios/appcenter-post-clone.sh) with the following content and push it to your source control.
Step 4: Configuring Build Settings
In the App Center dashboard, navigate to the "Build" section for your iOS app.
You'll see your iOS project readily available under the "Build app" section. This indicates successful integration.
Configure any additional build settings as needed within the App Center.
Here, enable the “Sign builds” option.
This option requires two files -
Provisioning Profiles (.mobileprovision)
Certificates (.p12)
The Apple Developer Portal provides a dedicated section for managing certificates, identifiers & profiles (commonly abbreviated as "Certificates, IDs & Profiles"). You can access this section to generate or download the necessary files for signing your iOS app in the App Center. (Check Step 5)
Step 5: Sign, Build and Distribute Your iOS App
Before building our iOS app, we need to make sure it's signed properly to run on a real device. Apps on iPhones and iPads, can only run if they have a digital signature created using Apple's code signing tools.
Generate a Certificate Signing Request (CSR): (Two Options)
Option 1 (Requires Xcode):
Open Xcode and navigate to Product > Create Signing Request.
Fill out the information and save the generated CSR file.
Option 2 (Without Xcode):
Open Keychain Access on your Mac.
Go to "Keychain Access" > "Certificate Assistant" > "Request a Certificate from a Certificate Authority."
Fill in the necessary details.
Save the CSR file to your computer.
Create a Certificate:
Login to your Apple Developer account and go to Certificates, Identifiers & Profiles.
Select Certificates > All > +.
Choose the appropriate certificate type (e.g., iOS App Development, Push Notifications).
Upload the CSR file (From Step 1).
Follow prompts to complete certificate creation.
Download and Install Certificate:
Download the issued certificate from the Developer Portal.
Double-click the certificate to install it in your Keychain Access.
Create a Provisioning Profile
In the Apple Developer Portal, navigate to Provisioning Profiles and create a new profile.
Select the app ID and certificate you created earlier.
Choose the devices or distribution method (App Store, Ad Hoc, etc.).
Download the generated provisioning profile.
Upload Signing Credentials
Upload the .p12 certificate file to your App Center dashboard in the "Signing" section as mentioned in the previous steps
Build and Distribute:
Initiate the build process for your Flutter iOS app using your chosen service.
Step 6: Distributing Your App (It's a Wrap!) 🚀
After a successful build, you can proceed to distribute your iOS app through App Center's distribution features.
With both Android and iOS setups complete, you've now successfully integrated App Center into your Flutter project. This integration empowers you with streamlined development, automated builds, and efficient app distribution for both major mobile platforms. Stay tuned for further exploration and tips to optimize your Flutter development experience!
Final Words: Building Amazing Apps Faster with Flutter and App Center
In this blog, we've explored the advantages of CI/CD for efficient software delivery and delved into two powerful tools: Flutter, the versatile native framework, and App Center, the comprehensive mobile app distribution platform by Microsoft.
However, the Flutter ecosystem offers a wealth of CI/CD options to choose from. Codemagic and fastlane are other popular choices, tailored specifically for mobile development. Additionally, Xcode Cloud integrates seamlessly for iOS development. Ultimately, the best CI/CD solution depends on your specific needs and preferences. By combining Flutter with a robust CI/CD pipeline, you can streamline your development process, accelerate delivery, and build amazing apps faster.
We've covered the step-by-step process of integrating App Center for distributing your Flutter applications on both Android and iOS platforms. While App Center excels at automation, there are scenarios where a manual approach might be preferred.
Manual approaches often involve:
Manual Build Generation: You'll need to initiate build commands directly through the Flutter CLI or your IDE.
Signing and Validating iOS Builds: For iOS builds, you'll need to handle signing and validation processes manually, which can add complexity.
The Benefits of App Center:
Even when considering manual distribution options, App Center can still be valuable. Here's how:
Shorten development cycles: Flutter's hot reload and App Center's automation features enable rapid development iteration and testing.
Ensure high-quality apps: Automated testing throughout the CI/CD pipeline helps identify and address bugs early on, leading to more robust and reliable apps.
Simplify app distribution: App Center streamlines app distribution to testers and various deployment environments.
Gain valuable insights: App Center's analytics and monitoring capabilities provide valuable user behavior and app performance data to guide future improvements.
Choosing Your Approach:
The best approach depends on your project's needs and development stage. App Center provides a robust automated solution, but manual distribution can be suitable for smaller projects or initial testing phases.
With Flutter and App Center working in tandem, you're well-equipped to craft stunning, high-performing mobile applications faster and more efficiently. Stay tuned for further explorations and insights into maximizing your Flutter development experience!
That's it folks!!!
Looking to scale your app development?
Hire Flutter app developers from F22 Labs to craft high-performance, cross-platform applications. Our team leverages the latest tools and best practices to deliver apps that meet your business goals efficiently. Let's bring your app idea to life!
Taha
Flutter Dev @ F22 Labs, solving mobile app challenges with a cup of coffee and a passion for crafting elegant solutions. Let's build something amazing together!
Partner with Us for Success
Experience seamless collaboration and exceptional results.