Publish your Flutter App - Android APK Signing and Release

flutter release apk
flutter release apk

How to sign the APK or app bundle created using flutter ?

To publish your app on Play Store, you need to give your app a digital signature.

step 1 : Create a new keystore file ; if you have an existing keystore then skip this step

  • Run command in your terminal for linux/mac
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
  • On Windows, use the following command:
keytool -genkey -v -keystore c:/Users/USER_NAME/key.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key
  • Fill in the required info inside the terminal
Enter keystore password: test@12345 
Re-enter new password: test@12345

What is your first and last name?
[test]: test
What is the name of your organizational unit?
[test]: test
What is the name of your organization?
[test]: test
What is the name of your City or Locality?
[test]: test
What is the name of your State or Province?
[test]: test
What is the two-letter country code for this unit?
[tt]: tt
Is CN=test, OU=test, O=test, L=test, ST=test, C=tt correct?
[no]: yes

//OUTPUT
Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days
for: CN=test, OU=test, O=test, L=test, ST=test, C=tt
[Storing /home/<user name>/key.jks]
  • Keep the keystore file private; do not check it into public source control.
  • Always keep a backup of the keystore file.
Command 'keytool' not found
run command :
sudo apt install openjdk-11-jre-headless
or
sudo apt install openjdk-8-jre-headless

step 2 : Reference the keystore from the app

  • Create a file name key.properties in your android folder
storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=key
storeFile=<location of the key store file, such as /Users/<user name>/key.jks>
  • Keep the key.properties file private; do not check it into public source control.
  • Always keep a backup of the key.properties file.

step 3 : Configure signing in gradle

Navigate to /android/app/build.gradle file.

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

android {
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now,
// so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}

step 4 : how to create APK file or Android App Bundle using flutter ?

  • How to build an android app bundle (AAB) using flutter ?
flutter build appbundle
  • How to build APK file using flutter ?
flutter build apk
flutter build apk --split-per-abi
  • armeabi-v7a (32-bit) APK
  • arm64-v8a (64-bit) APK

Bonus Tip : Do not forget to :

  1. Application Name [android : label in <application> tag]
  2. uses-permission [Permission requested by your app]
  • Review the build configuration, Gradle build file, build.gradle, located in <app dir>/android/app
  1. applicationId - unique app id
  2. versionCode & versionName - Setting the version property in pubspec.yaml
  3. minSdkVersion & targetSdkVersion - API level on which your app is designed to run

Useful Resources

Flutter Official Docs - Deployment Guide

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
AkshatApp

AkshatApp

Helping designers and developers build high quality websites and cross platform mobile apps with our step-by-step developer guides 📚 at akshatapp.com