Drop us a line
CI/CD and want
to be featured
in our blog?
Continuous integration and delivery (CI/CD) for Flutter apps with Nevercode
Flutter is an open-source, multi-platform, mobile SDK which can be used to build iOS and Android apps with the same source code. Flutter was around since long but it has started getting more attention since Google I/O 2018 when Google announced release preview of Flutter. There were also a few talks on how Flutter can be used to easily build beautiful cross-platform apps. Although Flutter has not released a stable version yet, some of the big companies like Alibaba, Groupon and many others started using Flutter. It clearly means that Flutter might have great potential and have a bright future. We can’t predict the future of Flutter but we have to be ready for Flutter sooner than later. We can build nice apps with Flutter but we also need to build, test and release Flutter apps effectively using best DevOps and CI/CD practices. In this post, we will see how we can build and test Flutter apps with Nevercode out of the box integration.
Sample Flutter app
Before we jump into Continuous Integration, we will create a demo Flutter app. Flutter has great getting started documentation on how to install and set up the environment for iOS and Android apps, we can demonstrate that easily. Flutter can be installed on Windows, Linux and macOS platform but we will use macOS.
Set up Flutter
The first step is to download Flutter SDK and unzip it to a suitable location on our disk. We can do this by using the following command:
$ curl -O https://storage.googleapis.com/flutter_infra/releases/beta/macos/flutter_macos_v0.7.3-beta.zip $ unzip flutter_macos_v0.7.3-beta.zip
Now that we have downloaded the Flutter SDK, we need to add Flutter to our
$PATH so that we can access Flutter globally. This varies from shell to shell, for bash, we can simply run this command:
$ export PATH=[PATH_TO_FLUTTER__DIRECTORY]/flutter/bin:$PATH
We can now access Flutter globally. The next thing is to set up iOS and Android environments as mentioned here. The flutter doctor command will guide you to the entire setup. Once all setup is done, you can run flutter doctor to make sure there are no issues.
Create Sample app
Flutter can generate boilerplate for the sample app by running the following commands:
$ flutter create your_app $ cd your_app $ flutter run
You can see the app running in the emulator/simulator or on devices. We have a similar app on Github that we will configure for continuous integration. The source code of the demo app can be found here.
Flutter continuous integration with Nevercode
Along with beautiful widgets for development, Flutter also offers amazing testing frameworks for unit testing, integration testing and widget testing to give regular feedback on development. The widget testing framework for Flutter is one of the great features which allows us to test widgets, user actions without going through UI. We can write awesome tests with Flutter but we also need to run those tests whenever an application has been changed. This is where continuous integration comes into the picture. There are very limited options for continuous integration for Flutter apps at the moment.
Nevercode is one of the cloud-based CI/CD services which provides out of the box support for Flutter apps. Nevercode also supports native iOS, Android, React Native, Cordova and Ionic apps. You can start with Nervecode with the free trial. Now let’s see how Nevercode can build and test the Flutter app we have just created.
Add our app
The demo app we have just created is publicly available on Github. If you have an app with submodules or a private repo, you will need to have additional setup like SSH key or username/password authentication. We can provide Flutter app URL to Nevercode to get started.
Once Nervercode gets the app source code, then it will start scanning our app source code in a fresh environment. Nevercode automatically detects the Flutter app and starts installing and building the required components.
Set up environment
Nevercode continuously updates build machines so that the latest build environments become available for us. Nervercode has Flutter environment pre-installed, so we don’t have to worry about installing Flutter and adding PATH variables on continuous integration environment. However, we can change the version of Flutter using the
FLUTTER_VERSION environment variable. We can build a specific scheme for iOS platform using the
NC_FLUTTER_SCHEME variable. In our demo project, we just need to build a default scheme so we don’t need to include that in the Environment section.
In the build configuration section, Nevercode has selected the default branch, project and configuration by scanning the app source code. If you want to override the branch, then you can select another branch. Nevercode can build both the Android and the iOS platform, however, we can limit it to the specific platform by selecting the checkbox in the build configuration. We also have some build scheduling options to trigger builds regularly.
Nevercode test configuration for Flutter projects is fully automated. We just have to enable the test target for Flutter test and it will build the specified target. In our demo app, it’s very simple as it’s a matter of ticking the box.
There are several other Nevercode features we can use, like code signing and publishing the reports to third-party services etc, but for this demo, we will cover just building and testing Flutter apps.
Build Flutter app
Now that we have easily configured a build for our demo project, we can choose the trigger of our choice or click on the Save and build button. Nevercode will start the build with the settings we have configured in the fresh VM and build and test our Flutter app. In the end, we will see that Nevercode has built both iOS and Android apps and has also run Flutter tests.
At the moment, Flutter doesn’t support any suitable format for test reporting that Nevercode can parse and display in the UI. However, we can see the test results in the console logs of Nevercode.
Nevercode also generates build artefacts, like the app file that we can download. Currently, our demo app hasn’t been code signed for release version for iOS, so it won’t generate the IPA file, but we can see debug APK files in the artefacts.
We have now successfully built and tested our Flutter app with Nevercode without any configuration or scripting hassle.
Flutter mobile SDK has potential to build beautiful, reactive and testable apps for both Android and iOS platform, and hassle-free CI services like Nevercode can speed up the development by providing continuous feedback. What’s your experience with using CI/CD for Flutter apps? Please share your thoughts in the comments below.
This article is written by Shashikant Jagtap.
Shashikant is DevOps practitioner for mobile apps and Director at XCTEQ Limited. He has automated release pipelines, implemented CI/CD and enabled DevOps cum Test Automation practices for many apps.
He blogs about mobile DevOps and CI/CD. Check-out XCTEQ for more: https://www.xcteq.co.uk/