Blog

Build Release Apk In Flutter

After making a complete app in Flutter, we all want to upload it to play store. But the thing is, when we build apk initially that one is debug apk by default not the release apk. While publishing app to playstore we need release apk and the procedure to make release apk are:

Create .jks File

Step I
At first we need to create keystore file which is of .jks format. So for this, we’ll run the below code in terminal:

//For windows:
keytool -genkey -v -keystore Part1 -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias PART2

PART1 means put the location of keystore.jks file. Instead of PART1 put like below:
D:\flutter\Demo\key.jks
Note: File location will be in backward slash “\”
PART2 means keystore file name.Instead of PART2 put key.
So the final code will be:

keytool -genkey -v -keystore D:\flutter\Demo\key.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key

Step II
After running that above code,you hit enter key. It will ask you to enter keystore password(for trial , I had entered demo0909). After entering password do remember that password and re-enter it.

Step III
In this step, it will ask you many question like first name, last name, organization name and so on. Answer all the 6 questions.

Step IV
In the step we will type Yes for the asked question.

Step V
In this step, you’ll have to enter key password(for trial key password is key0909) and do remember this also and re-enter that again.

After this ,.jks file has been created to the location you had put in the first step.

Create key.properties File

Go inside android folder and create key.properties file. Write the code like this:

storePassword=demo0909
keyPassword=key0909
keyAlias=key
storeFile=D:/flutter/Demo/key.jks

Note: File location in the storeFile will be in forward slash “/”

Release Apk Setup

Go inside app level build.gradle file. Add 3 after line containing apply plugin text:

def keystorePropertiesFile = rootProject.file(“key.properties”)
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))



Under android add one function called signingConfigs and replace debug with release under buildTypes{release{…}}like this:

android{
...
defaultConfig{
...
}
signingConfigs{
 release{
 keyAlias keystoreProperties['keyAlias']
 keyPassword keystoreProperties['keyPassword']
 storeFile file(keystoreProperties['storeFile'])
 storePassword keystoreProperties['storePassword']
 }
}
buildTypes {
 release {
  signingConfig signingConfigs.release
 }
}
}


Build Release Apk

After doing all the above steps, go to the terminal and run the below command to get release apk:

flutter build apk --release

or

flutter build appbundle --release

After this, you will get the release apk and you will publish it to playstore with no issue.

Thank you.
Keep Coding and Keep Learning




        

This Post Has 0 Comments

Leave A Reply