Flutter Brew

broken image


Contents

From this guide, you'll learn how to set up CI/CD for Flutter with the help of Fastlane and Firebase App Distribution. Brew tap adoptopenjdk/openjdk. 3 # see available versions. Flutter is becoming a serious developer platform and with it grows a need for Flutter databases. A quick note on Flutter and Dart as it is pretty young and you might either be looking for a Flutter database, a Dart database or truly a Flutter Dart database. Flutter is an open-source UI software development kit created by Google.

  • fastlane

Follow continuous delivery best practices with Flutter to make sure yourapplication is delivered to your beta testers and validated on a frequent basiswithout resorting to manual workflows.

fastlane

This guide shows how to integrate fastlane, anopen-source tool suite, with your existing testing and continuous integration(CI) workflows (for example, Travis or Cirrus).

Local setup

It's recommended that you test the build and deployment process locally beforemigrating to a cloud-based system. You could also choose to perform continuousdelivery from a local machine.

  1. Install fastlane gem install fastlane or brew install fastlane.Visit the fastlane docs for more info.
  2. Create your Flutter project, and when ready, make sure that your project builds via
    • flutter build appbundle; and
    • flutter build ios --release --no-codesign.
  3. Initialize the fastlane projects for each platform.
    • In your [project]/android directory, run fastlane init.
    • In your [project]/ios directory, run fastlane init.
  4. Edit the Appfiles to ensure they have adequate metadata for your app.
    • Check that package_name in [project]/android/fastlane/Appfile matches your package name in AndroidManifest.xml.
    • Check that app_identifier in [project]/ios/fastlane/Appfile also matches Info.plist's bundle identifier. Fill in apple_id, itc_team_id, team_id with your respective account info.
  5. Set up your local login credentials for the stores.
    • Follow the Supply setup steps and ensure that fastlane supply init successfully syncs data from your Play Store console. Treat the .json file like your password and do not check it into any public source control repositories.
    • Your iTunes Connect username is already in your Appfile's apple_id field. Set the FASTLANE_PASSWORD shell environment variable with your iTunes Connect password. Otherwise, you'll be prompted when uploading to iTunes/TestFlight.
  6. Set up code signing.
    • On Android, there are twosigning keys: deployment and upload. The end-users download the .apk signedwith the ‘deployment key'. An ‘upload key' is used to authenticate the .aab / .apkuploaded by developers onto the Play Store and is re-signed with thedeployment key once in the Play Store.
      • It's highly recommended to use the automatic cloud managed signing forthe deployment key. For more information,see the official Play Store documentation.
      • Follow the key generationstepsto create your upload key.
      • Configure gradle to use your upload key when building your app inrelease mode by editing android.buildTypes.release in[project]/android/app/build.gradle.
    • On iOS, create and sign using adistribution certificate instead of a development certificate when you'reready to test and deploy using TestFlight or App Store.
      • Create and download a distribution certificate in yourApple Developer Account console.
      • open [project]/ios/Runner.xcworkspace/ and select the distributioncertificate in your target's settings pane.
  7. Create a Fastfile script for each platform.
    • On Android, follow thefastlane Android beta deployment guide.Your edit could be as simple as adding a lane that callsupload_to_play_store.Set the aab argument to ../build/app/outputs/bundle/release/app-release.aabto use the app bundle flutter build already built.
    • On iOS, follow thefastlane iOS beta deployment guide.Your edit could be as simple as adding a lane that calls build_ios_app withexport_method: 'app-store' and upload_to_testflight. On iOS an extrabuild is required since flutter build builds an .app rather than archiving.ipas for release.

You're now ready to perform deployments locally or migrate the deploymentprocess to a continuous integration (CI) system.

Running deployment locally

  1. Build the release mode app.
    • flutter build appbundle.
    • flutter build ios --release --no-codesign. No need to sign now since fastlane will sign when archiving.
  2. Run the Fastfile script on each platform.
    • cd android then fastlane [name of the lane you created].
    • cd ios then fastlane [name of the lane you created].

Cloud build and deploy setup

First, follow the local setup section described in ‘Local setup' to make surethe process works before migrating onto a cloud system like Travis.

The main thing to consider is that since cloud instances are ephemeral anduntrusted, you won't be leaving your credentials like your Play Store serviceaccount JSON or your iTunes distribution certificate on the server.

Continuous Integration (CI) systems, such as Cirrusgenerally support encrypted environment variables to store private data.

Take precaution not to re-echo those variable values back onto the console inyour test scripts. Those variables are also not available in pull requestsuntil they're merged to ensure that malicious actors cannot create a pullrequest that prints these secrets out. Be careful with interactions with thesesecrets in pull requests that you accept and merge.

  1. Make login credentials ephemeral.
    • On Android:
      • Remove the json_key_file field from Appfile and store the stringcontent of the JSON in your CI system's encrypted variable. Use thejson_key_data argument in upload_to_play_store to read theenvironment variable directly in your Fastfile.
      • Serialize your upload key (for example, using base64) and save it asan encrypted environment variable. You can deserialize it on your CIsystem during the install phase with
    • On iOS:
      • Move the local environment variable FASTLANE_PASSWORD to useencrypted environment variables on the CI system.
      • The CI system needs access to your distribution certificate.fastlane's Match system isrecommended to synchronize your certificates across machines.
  2. It's recommended to use a Gemfile instead of using an indeterministicgem install fastlane on the CI system each time to ensure the fastlanedependencies are stable and reproducible between local and cloud machines.However, this step is optional.
    • In both your [project]/android and [project]/ios folders, create aGemfile containing the following content:
    • In both directories, run bundle update and check both Gemfile andGemfile.lock into source control.
    • When running locally, use bundle exec fastlane instead of fastlane.
  3. Create the CI test script such as .travis.yml or .cirrus.yml in yourrepository root.
    • Shard your script to run on both Linux and macOS platforms.
    • Remember to specify a dependency on Xcode for macOS (for exampleosx_image: xcode9.2).
    • See fastlane CI documentation for CI specific setup.
    • During the setup phase, depending on the platform, make sure that:
      • Bundler is available using gem install bundler.
      • For Android, make sure the Android SDK is available and the ANDROID_SDK_ROOTpath is set.
      • Run bundle install in [project]/android or [project]/ios.
      • Make sure the Flutter SDK is available and set in PATH.
    • In the script phase of the CI task:
      • Run flutter build appbundle orflutter build ios --release --no-codesign,depending on the platform.
      • cd android or cd ios
      • bundle exec fastlane [name of the lane]

Reference

See the Flutter framework repository's Cirrus script.

Other services

The following are some other options available to help automatethe delivery of your application.

  • GitHub Actions- CI/CD on GitHubGet an Example Project

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.

Inspired by SwiftGen.

Flutter Brewing

Motivation #

Using asset path string directly is not safe.

Bad
What would happen if you made a typo?

Flutter Brew

⭕️ Good
We want to use it safely.

Installation #

Homebrew #

Flutter Brew

Flutter

Flutter Brewery

Works with MacOS and Linux.

Pub Global #

Works with MacOS, Linux and Windows.

You might need to set up your path.

As a part of build_runner #

  1. Add build_runner and FlutterGen to your package's pubspec.yaml file:
  1. Install FlutterGen
  1. Use FlutterGen

Usage #

Run fluttergen after the configuration pubspec.yaml.

Configuration file #

FlutterGen generates dart files based on the key flutter and flutter_gen of pubspec.yaml.
Default configuration can be found here.

Available Parsers #

Assets #

Flutter

Just follow the doc Adding assets and images#Specifying assets to specify assets, then FlutterGen will generate related dart files.
No other specific configuration is required.
Ignore duplicated.

These configurations will generate assets.gen.dart under the lib/gen/ directory by default.

Usage Example

FlutterGen generates Image class if the asset is Flutter supported image format.

Example results of assets/images/chip.jpg:

Flutter Brewing Company

  • Assets.images.chip is an implementation of AssetImage class.
  • Assets.images.chip.image(...) returns Image class.
  • Assets.images.chip.path just returns the path string.
Brew

If you are using SVG images with flutter_svg you can use the integration feature.

Available Integrations

PackagesFile extensionSettingUsage
flutter_svg.svgflutter_svg: trueAssets.images.icons.paint.svg()
flare_flutter.flrflare_flutter: trueAssets.flare.penguin.flare()


In other cases, the asset is generated as String class.

FlutterGen also support generating other style of Assets class:

The root directory will be omitted if it is either assets or asset.

Example of code generated by FlutterGen

Fonts #

Just follow the doc Use a custom font to specify fonts, then FlutterGen will generate related dart files.
No other specific configuration is required.
Ignore duplicated.

Flutter App Brewery Github

These configurations will generate fonts.gen.dart under the lib/gen/ directory by default.

Usage Example

Flutter Brew Cask

Example of code generated by FlutterGen

Colors #

FlutterGen supports generating colors from XML format files.
Ignore duplicated.

FlutterGen can generate a Color class based on the name attribute and the color hex value.If the element has the attribute type, then a specially color will be generated.

Currently supported special color types:

Noticed that there is no official material color generation algorithm. The implementation is based on the mcg project.

These configurations will generate colors.gen.dart under the lib/gen/ directory by default.

Brew

⭕️ Good
We want to use it safely.

Installation #

Homebrew #

Flutter Brew

Flutter Brewery

Works with MacOS and Linux.

Pub Global #

Works with MacOS, Linux and Windows.

You might need to set up your path.

As a part of build_runner #

  1. Add build_runner and FlutterGen to your package's pubspec.yaml file:
  1. Install FlutterGen
  1. Use FlutterGen

Usage #

Run fluttergen after the configuration pubspec.yaml.

Configuration file #

FlutterGen generates dart files based on the key flutter and flutter_gen of pubspec.yaml.
Default configuration can be found here.

Available Parsers #

Assets #

Just follow the doc Adding assets and images#Specifying assets to specify assets, then FlutterGen will generate related dart files.
No other specific configuration is required.
Ignore duplicated.

These configurations will generate assets.gen.dart under the lib/gen/ directory by default.

Usage Example

FlutterGen generates Image class if the asset is Flutter supported image format.

Example results of assets/images/chip.jpg:

Flutter Brewing Company

  • Assets.images.chip is an implementation of AssetImage class.
  • Assets.images.chip.image(...) returns Image class.
  • Assets.images.chip.path just returns the path string.

If you are using SVG images with flutter_svg you can use the integration feature.

Available Integrations

PackagesFile extensionSettingUsage
flutter_svg.svgflutter_svg: trueAssets.images.icons.paint.svg()
flare_flutter.flrflare_flutter: trueAssets.flare.penguin.flare()


In other cases, the asset is generated as String class.

FlutterGen also support generating other style of Assets class:

The root directory will be omitted if it is either assets or asset.

Example of code generated by FlutterGen

Fonts #

Just follow the doc Use a custom font to specify fonts, then FlutterGen will generate related dart files.
No other specific configuration is required.
Ignore duplicated.

Flutter App Brewery Github

These configurations will generate fonts.gen.dart under the lib/gen/ directory by default.

Usage Example

Flutter Brew Cask

Example of code generated by FlutterGen

Colors #

FlutterGen supports generating colors from XML format files.
Ignore duplicated.

FlutterGen can generate a Color class based on the name attribute and the color hex value.If the element has the attribute type, then a specially color will be generated.

Currently supported special color types:

Noticed that there is no official material color generation algorithm. The implementation is based on the mcg project.

These configurations will generate colors.gen.dart under the lib/gen/ directory by default.

Usage Example

Example of code generated by FlutterGen

Default Configuration #

The following are the default settings.The options you set in pubspec.yaml will override the corresponding default options.

Credits #

The material color generation implementation is based on mcg and TinyColor.

Issues #

Please file FlutterGen specific issues, bugs, or feature requests in our issue tracker.

Plugin issues that are not specific to FlutterGen can be filed in the Flutter issue tracker.

Contributing #

We are looking for co-developers.

If you wish to contribute a change to any of the existing plugins in this repo,please review our contribution guideand open a pull request.





broken image