DevOps

DevOps #

Commands #

There are a bunch of flutter commands that are useful for creating pipelines. Here is a quick overview.

CommandDescription
flutter doctorShows diagnostics.
flutter pub getInstall dependencies from pubspec.yaml
flutter testRun unit and widget tests.
flutter build apkBuild installable package for Android.
flutter build webBuild project to static HTML and JavaScript.

Testing #

See Testing Flutter apps for an overview of the different kinds of testing.

Running specific tests #

Just running flutter test will execute tests in the test folder. You can append a path to only run specific tests. Example:

flutter test test/widget_test.dart

Coverage #

You can get a code coverage report for the tests with:

flutter test --coverage

It will generate a coverage report in lcov format. You will find the output at coverage/lcov.info. It looks like this:

SF:lib/main.dart
DA:1,1
DA:2,1
LF:2
LH:2
end_of_record

Not very human friendly. You can turn it into HTML with:

genhtml ./coverage/lcov.info -o ./coverage/html

You will find the index at coverage/html/index.html and it looks like this:

The genhtml command is part of the aforementioned lcov package. So it needs to be available. How you do that, depends on the OS.

Windows

In git-bash:

Download https://github.com/jgonzalezdr/lcov/releases/download/v1.15.alpha1w/lcov-1.15.alpha1w.zip

Extract to C:\Users\<your username>\lcov

Then you can do:

~/lcov/genhtml ./coverage/lcov.info -o ./coverage/html

macOS

brew install lcov

Assuming you have Homebrew installed.

Debian/Ubuntu

apt install lcov

Integration test #

Integration test in the Flutter world, means that you run tests on a real (or emulated) device.

What you need to do, depends a bit on the platform.

Web #

Before executing tests you need ChromeDriver downloaded and running. See here.

Mobile #

I don’t have a good solution here.

You could try Firebase Test Lab. But, free quota is pretty low.

See pricing for Test Lab.

Build/Release #

Web #

Just run flutter build web then upload files in build/web to a static web host.

You can find instructions on deployment to Firebase hosting here.

You can get a token, that can be used to deploy from CI/CD with:

firebase login:ci

Configure the token as an environment variable named FIREBASE_TOKEN in your CI/CD pipeline. Then deploy from your pipeline with:

firebase deploy --token "$FIREBASE_TOKEN"

Links:

iOS #

It’s complicated

Android #

Android uses a package format called APK. You can simply bundle your app to an APK then copy it to a Android device and install it.

flutter build apk

Then upload build/app/outputs/flutter-apk/app-release.apk to somewhere.

You can make the bundle size smaller by building individual APKs per hardware platform.

flutter build apk --split-per-abi

Here is the size difference for a basic app.

APK split per ABI

Note: most newer phones are running 64 bit ARM, so they will use the app-arm64-v8a-release.apk.

APKs needs to be digitally signed before they can be put on Play Store. I think that is out of scope.

Monitoring #

Monitoring is important to detect defects early, optimize performance and gain insight for improving user experience.

Google got two great services under the Firebase umbrella. Check out the links:

Drone CI #

Here is a minimal pipeline that test and build a Flutter project.

kind: pipeline
type: docker
name: default

steps:
  - name: test
    image: instrumentisto/flutter:3.19
    commands:
      - flutter doctor
      - flutter pub get
      - flutter test
  - name: build
    image: instrumentisto/flutter:3.19
    commands:
      - flutter pub get
      - flutter build apk

I couldn’t find an official Flutter image. However, instrumentisto/flutter seems like an okay option. It is based on Ubuntu 22.04, got Android SDK and latest version of Flutter build in. Not the most minimal image though.