This article explains how to create Flutter application template with GitHub Actions to save yourself time and nerves.
Getting started
- Sample application used in this tutorial Flutter CI Test
- Create flutter application
- You can use flutter_flavorizr to generate Android/iOS flavors. Sample configuration with firebase support can be found in pubspec.yaml
Create Firebase project
- Here you can create Firebase project. Make sure that project belongs to your organization.
- Create Firebase apps (one per flavor and platform e.g. Android dev, iOS dev, Android staging, iOS staging etc.) in Firebase overview https://console.firebase.google.com/project/{project_name}/overview.
Follow steps in creator to download config files and add Firebase SDK to flutter app. More details here - Create “alpha-testers” and “beta-testers” groups in Firebase App Distribution.
Google Play Console
- Create application in Google Play Console Make sure that project belongs to your organization.
- Generate debug and upload key
- Update signingConfigs and buildTypes in android/app/build.gradle.
signingConfigs {
release {
storeFile file("upload-key.jks")
keyAlias System.getenv("KEYSTORE_KEY_ALIAS") ?: localProperties.getProperty("KEYSTORE_KEY_ALIAS")
keyPassword System.getenv("KEYSTORE_KEY_PASSWORD") ?: localProperties.getProperty("KEYSTORE_KEY_PASSWORD")
storePassword System.getenv("KEYSTORE_STORE_PASSWORD") ?: localProperties.getProperty("KEYSTORE_STORE_PASSWORD")
}
debug {
storeFile file("${project.rootDir.absolutePath}/debug.keystore")
keyAlias "androiddebugkey"
keyPassword "android"
storePassword "android"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.debug
debuggable true
minifyEnabled false
multiDexEnabled true
testCoverageEnabled false
}
}
Google Cloud Platform
- In android directory execute
fastlane init
- Add firebase app distribution plugin
fastlane add_plugin firebase_app_distribution
- Add to Gemfile fastlane version e.g.
gem "fastlane", "=2.200.0"
- Add to android/fastlane/Pluginfile firebase app distribution version e.g.
gem 'fastlane-plugin-firebase_app_distribution', "=0.3.2"
- Copy android/fastlane/Fastfile from Flutter CI Test to your app
- Run
gem install bundler -v 2.3.0
nextbundle install
and add generated ios/Gemfile.lock to VCS - Setup fastlane supply
- Provide information about app in Google Play
Enable Google Play Android Developer API in Google Cloud Platform.
App Store Connect
- Create App ids (must be the same as you created in Firebase App Distribution) here.
- Create app in App Store Connect.
- Create App Store Connect API Key and set App Store Connect API variables (GitHub secrets).
iOS fastlane configuration
- In ios directory execute
fastlane init
- Add firebase app distribution plugin
fastlane add_plugin firebase_app_distribution
- Add to Gemfile fastlane version e.g.
gem "fastlane", "=2.200.0"
- Add to ios/fastlane/Pluginfile firebase app distribution version e.g.
gem 'fastlane-plugin-firebase_app_distribution', "=0.3.2"
- Copy ios/fastlane/Fastfile from Flutter CI Test to your app
- Set team ID in ios/fastlane/Appfile Team ID can be found here
- Run
gem install bundler -v 2.3.0
nextbundle install
and add generated ios/Gemfile.lock to VCS - Setup fastlane match
More information about fastlane configuration can be found here
Set required environment variables (GitHub secrets)
- Services accounts Firebase App Distribution Service Account json key currently the same for all flavors
CI_TEST_FIREBASE_SERVICE_ACCOUNT_PRODUCTION
CI_TEST_FIREBASE_SERVICE_ACCOUNT_STAGING
CI_TEST_FIREBASE_SERVICE_ACCOUNT_DEVELOPMENT
- Firebase application ID (available in Firebase Project settings)
CI_TEST_ANDROID_FIREBASE_APP_ID_PRODUCTION
CI_TEST_ANDROID_FIREBASE_APP_ID_STAGING
CI_TEST_ANDROID_FIREBASE_APP_ID_DEVELOPMENT
CI_TEST_IOS_FIREBASE_APP_ID_PRODUCTION
CI_TEST_IOS_FIREBASE_APP_ID_STAGING
CI_TEST_IOS_FIREBASE_APP_ID_DEVELOPMENT
- Upload Key (keystore)
KEYSTORE_KEY_ALIAS
– set when generating upload keyKEYSTORE_KEY_PASSWORD
– set when generating upload keyKEYSTORE_STORE_PASSWORD
– set when generating upload keyUPLOAD_KEYSTORE_FILE
– android upload key encoded in base64
- Play Store publisher account json key (service account json key generated in setup fastlane supply step)
CI_TEST_GOOGLE_DEVELOPER_SERVICE_ACCOUNT_ACTOR_FASTLANE
- App store (variables for App Store Connect Api, should be set during creating App Store Connect API Key)
APP_STORE_CONNECT_API_KEY_ISSUER_ID
APP_STORE_CONNECT_API_KEY_KEY
APP_STORE_CONNECT_API_KEY_KEY_ID
MATCH_PASSWORD
– password to decrypt profiles, created during setup fastlane matchFASTLANE_MATCH_GIT_DEPLOY_KEY
– Certificates repository deploy key (read-only), created during setup fastlane match
- API URLs
CI_TEST_API_URL_PRODUCTION
CI_TEST_API_URL_STAGING
CI_TEST_API_URL_DEVELOPMENT
GitHub Actions
GitHub Actions workflows are located in .github/workflows directory.
There are 8 workflows:
- android-alpha.yml – Build and deploy android app alpha version
- android-beta.yml – Build and deploy android app beta version
- android-prod.yml – Build and deploy android app prod version
- ios-alpha.yml – Build and deploy ios app alpha version
- ios-beta.yml – Build and deploy ios app beta version
- ios-prod.yml – Build and deploy ios app prod version
- linter.yml – Static code analyse in pull requests, uses rules defined in the project in analysis_options.yaml
- release-tag.yml – Create git tag for release versions (extract version from pubspec.yaml as tag name)
Future improvements
Currently GitHub Actions doesn’t support environment variables (non-secret) that can be shared between workflows, so environment variables must be set for each workflow e.g.
env:
FLUTTER_CHANNEL: 'stable'
FLUTTER_VERSION: '2.8.1'
JAVA_VERSION: '17.0.1+12'
RUBY_VERSION: '3.0.3'
BUNDLER_VERSION: '2.3.0'
There you go. You should be able to create an app template using GitHub Actions yourself now. You’re welcome to comment this post. I’ll do my best to answer promptly.
Popular posts
From Hype to Hard Hats: Practical Use Cases for AI chatbots in Construction and Proptech.
Remember the multimedia craze in the early 2000s? It was everywhere, but did it truly revolutionize our lives? Probably not. Today, it feels like every piece of software is labeled "AI-powered." It's easy to dismiss AI chatbots in construction as just another tech fad.
Read moreFears surrounding external support. How to address concerns about outsourcing software development?
Whether you’ve had bad experiences in the past or no experience at all, there will always be fears underlying your decision to outsource software development.
Read moreWhat do you actually seek from external support? Identify what’s preventing you from completing a project on time and within budget
Let’s make it clear: if the capabilities are there, a project is best delivered internally. Sometimes, however, we are missing certain capabilities that are required to deliver said project in a realistic timeline. These may be related to skills (e.g. technical expertise, domain experience), budget (hiring locally is too expensive) or just capacity (not enough manpower). What are good reasons for outsourcing software development?
Read more