How to sign and deploy your Flutter app

Introduction

App-signing, building artifacts and releasing your app to Google & Apple is not that tuff like hell .This article will only cover deploying your app to the Google Play Store Release ( i will write about Apple App Store Release soon).
please see and follow the official Flutter docs.

Keep in mind that the Google Play Store requirements evolve over time, please Google if you encounter any errors. Good luck 🙂 .I generally find StackOverflow and Flutter dev forum to provide the best answers.

So Let’s Begin

i. Generate your keystore

Every app needs to be digitally signed by its own keystore (a .jks file) before being uploaded to Google or Apple. When you deploy newer versions, they will use the digital signature to verify the authenticity of the upload. Therefore DO NOT lose this file( i keep my all .jks files in cloud dropbox , google drive after losing few of them 😅 ) and DO NOT check it into version control, keep a copy of it somewhere safe. If you lose this file, you will need to generate a new one and contact Google and Apple to get it verified. Prepare and write down a key password and store password, you will need to use this in the next step Run the following command to generate your keystore file. Make sure you replace nutella with the name of your app in both the keystore argument and the alias argument. After running this command your file will be saved in ~ or C:/Users/USER_NAME change the directory if desired.

Run the following command to generate your keystore on Mac/Linux:

keytool -genkey -v -keystore ~/demoapp.jks -keyalg RSA -keysize 2048 -validity 3000 -alias demoapp

Run this on Windows (replace USER_NAME with your username):

keytool -genkey -v -keystore C:/Users/USER_NAME/demoapp.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 3000 -alias demoapp

ii.Create keystore properties file

Create a new file {project-root}/android/key.properties with the following and replace each field with the details from the previous step.
Keep in Mind DO NOT check this file into version control.

storePassword=secret
keyPassword=secret
keyAlias=demoapp
storeFile=C:\\Users\\USER_NAME\\Desktop\\demoapp.jks

iii.Update build.gradle

  1. Set compileSdkVersionminSdkVersion , and targetSdkVersion to 29. See the documentation for correct Android versioning.
  2. Open {project-root}/android/app/build.gradle
  3. Under defaultConfig, replace the buildTypes block with this fragment of code (use androidx.fragment:fragment:1.0.0 instead of com.android.support:support-fragment:29.0.0 when using AndroidX):
signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }

4. Add this block before

android {
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

iv.Update Pubspec.yaml

Open pubspec.yaml and update the version, the first part before the + sign is the version name, I recommend using semantic versioning. And increment the number after the + sign, it is the version code and if it is not updated Google/Apple could reject your APK. Please see https://flutter.dev/docs/deployment/android#updating-the-apps-version-number or https://stackoverflow.com/questions/54357468/how-to-set-build-and-version-number-of-flutter-app for more information.

Typically I like to update my version name semantically, either incrementing the major or minor number like 1.1.0 -> 1.2.0, if it has breaking changes 1.1.0 -> 2.0.0 etc. And I always increment the version number like +1 to +2 or+3 .

v. Build and upload APK to Google Play

  1. Run this in command line in your project root flutter clean && flutter build appbundle --release, this could take up to 10 minutes or more , don’t freak out, keep patience 😬
  2. Login to Google Play Console
  3. Click on ‘Release Management’ on the left hand side, then ‘App releases’
  4. Then create a new release, and fill in the details, I like to use the version name as the release name.
  5. Upload your appbundle files in this directory: {project-root}/build/app/output/bundle/release/app-release.aab
  6. You need to submit screenshots and do ratting part , price and distribution Practise your Googling skills to fix any issues
  7. Cheers 🎉

Deployments Tips subsequent

  1. Update version name and version number in pubspec.yaml
  2. Run flutter clean && flutter build appbundle --release
  3. Go to Google Play Console -> Release Management -> Create new release
  4. Upload new your-app-folder/build/app/output/bundle/release/app-release.aab files
  5. Checkin changes and wait for my apple app store publish blog post

Happy Fluttering!

Leave a Comment

Your email address will not be published. Required fields are marked *