Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Continuous Integration with Flutter using Gitlab

Pascal Welsch
February 12, 2019

Continuous Integration with Flutter using Gitlab

mobile.cologne Februrary 12th
https://mobile.cologne/2019-02-12-vortragsabend

Pascal (@passsy) presents how to build a Continuous Integration Pipeline for Flutter.

flutter build
flutter test
flutter analyze

He creates a sample project and builds it on gitlab CI, for Android and iOS.

Pascal Welsch

February 12, 2019
Tweet

More Decks by Pascal Welsch

Other Decks in Programming

Transcript

  1. Flutter app code Real Flutter Codebase iOS embedder Android embedder

    Fuchsia embedder Windows embedder Plugin Plugin Plugin Plugin Plugin Plugin Plugin Plugin Plugin Plugin Plugin Plugin
  2. Embedder App App code (Dart) Flutter Core Assets Plugins Platform

    code Flutter SDK Embedder SDK Responsibility
  3. CI steps - Build app - Run unit tests -

    Run UI tests - Run static analysis - Code coverage - Lint - Danger
  4. Difficulties of CI in mobile development - Android Emulator required

    for Instrumentation Tests - iOS Simulator required for iOS UI Tests - iOS apps can’t be build on linux Jenkins, one of the few solutions offering, runners on OSX
  5. Flutter CI - Tests (even UI tests) run headless on

    every OS - Building/Testing embedder apps requires embedder SDK tools - For iOS/Mac apps you need macOS - For Android you need the Android SDK - For Windows you need new hardware every year
  6. Which CI is good for Flutter? - Travis CI -

    CircleCi - Jenkins - GitLab CI - GitHub Actions - you name it...
  7. Which CI? Any CI, but I’ll focus on GitLab CI

    for today Let’s assume the following is given: $ echo “Let’s build” $ git clone [email protected]:passsy/flutter-app.git
  8. What flutter doesn’t require - Dart - Flutter engine -

    Java - Android SDK * - Xcode toolchain * * Optional
  9. Make your CI builds reproducible! Never use latest Let all

    developers and CI use the same flutter version Make flutter part of your project
  10. Flutter wrapper github.com/passsy/flutter_wrapper - single executable flutterw which downloads the

    correct version before executing flutter - Version is part of your repository (submodule)
  11. $ flutter build -h Available subcommands: aot Build an ahead-of-time

    compiled snapshot of your app's Dart code. apk Build an Android APK file from your app. bundle Build the Flutter assets directory from your app. ios Build an iOS application bundle (Mac OS X host only).
  12. Execute it on Jenkins pipeline { agent { docker "cirrusci/flutter"}

    stages { stage(“pr”) { sh ‘ci/pr.sh’ } } }
  13. Docker! - Use Docker to build your flutter app -

    Except for iOS builds - Allows building it locally (gitlab-runner) - Works on almost every modern CI
  14. Improve our build_flutter.sh #!/bin/bash set -e flutter format lib flutter

    analyze flutter test --coverage flutter build android
  15. Improve build script ./flutterw test --coverage # parse and show

    code coverage (via lcov) genhtml -o coverage/html coverage/lcov.info
  16. Create releases (android) - release_android.sh - Use gradle plugin to

    publish to play store github.com/Triple-T/gradle-play-publisher - ./gradlew publishApk
  17. Create releases (ios) - Use what Sebastian suggested in his

    talk - Fastlane - xcbuild is your friend
  18. Codemagic - It works - Runs tests, builds apps -

    Easy way to get running for iOS without a Mac - I don’t trust them