Are you tired of deploying flutter app on stores again and again?
Tags: flutter, programming, dart
Published: 2022-12-20 13:25:54

Often apps need to do changes after deploying sometimes to fix bugs sometime to add new features, but the process of deploying is same and doing it multiple time takes time.
So lets get rid of the problem by a using Fastlane and implement CD on the app.
Fastlane?
The official documents of flutter suggests Fastlane for CD, here.

Before we start here are the things you need to before implementing CD to your app,
Gem for installing Fastlane(We will cover it).
Google Developer Account.

Installing Gem and Fastlane:
Download the latest version of ruby from here and install it,

To confirm install of Ruby, use
ruby -v
now check gem, because its installed with ruby,
gem -v
Lets install Fastlane with gem,
gem install fastlane
Initializing Fastlane in flutter project:
This set requires a Json Secret file of google play console,
So go to Google Play Console , in Account Details, Setup, API access,
Create new service account,
follow the setup here, and download your Json file in project directory
Open flutter project directory and on terminal use (cd android/ios)
cd android 
fastlane init
Now enter your package name,
Enter the Path of your Json Secret File(The one we downloaded from play console),
Its up to you choose the metadata option ,I used
N
Now press enter until Fastlane initializes,
Just to be sure cross check that in android/fastlane/Appfile package name is same as it is on store,
Lets setup code signing for stores,
In terminal use,
keytool -genkey -v -keystore %userprofile%\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload
and remember the password,
create a file named key.properties in [project]/android/key.properties
add this in the file (change password and path),
storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=upload
storeFile=<location of the key store file, such as /Users/<user name>/upload-keystore.jks>
if you are confused for generating the keystore files you see more details here,
And change app/build.gradle file,
as given here,
Add the keystore information from your properties file before the android block,
def keystoreProperties = new Properties()
 def keystorePropertiesFile = rootProject.file(‘key.properties’)
 if (keystorePropertiesFile.exists()) {
 keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
 }
android {
 …
 }
Load the key.propertie asas file into the keystoreProperties object,
and in buildTypes block,
   signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }
now do flutter clean once,
and build your flutter app,
now change the fastlane file and add this,
lane :beta do 
  gradle(task: ‘assemble’, build_type: ‘Release’) 
  upload_to_play_store(track: ‘beta’) 
end
Adjust the build_type and flavorparams as needed to build the right APK for your setup,You can make custom lanes as you need
now in termial,
flutter build appbundle
fastlane beta
Well here we go this will upload in beta change as per requirement,
you can also automate this with cloud platforms just add your jsonkeyfile to env variables and change it on FASTLANE APPFILE
and in script add this,
source https://rubygems.org
gem fastlane
flutter build appbundle
cd android
bundle exec fastlane [name of the lane]
for more details visit
Thanks you.