Generate signed APK/ABB in flutter

CodingWithTashi
4 min readMay 29, 2023

--

Generating a signed APK/ABB with Flutter can indeed be a challenging task, especially if you lack experience with native Android development.

It requires understanding of the Android build process, key management, and various configuration settings.

Without prior knowledge of these aspects, the process can be time-consuming.

generate sign apk in flutter
Photo by Cytonn Photography on Unsplash

Hello guys, this is CodingWithTashi and in this shitty post, we are going to learn how to generate signed APK/ABB for your flutter app before publishing.

[Background story]

The other day, I was attempting to publish an application on the Play Store. However, I encountered some difficulty in generating a new signed APK/ABB file.

Although I have gone through this configuration process multiple times before, I often find myself forgetting the necessary steps.

To alleviate this issue, I decided to write this shitty post as a reference for my future self, in the hopes that it may also assist others facing a similar challenge. With this guide, I aim to make the process smoother and more efficient

We will try to wrap this post in three category

  1. Configuring build.gradle
  2. Generating jks file
  3. Generating release APK/ABB

1. Configuring build.gradle

In android -> app -> build.gradle

  • If you notice here, Default buildTypes release signingConfig is set to debug by default.
  • To be able to generate signed release APK/ABB, we will need to update from debug to release as shown below.
  • You can do it by simply updating debug to release .
  • But wait, If you try to generate APK/ABB at this point, you will get an error with message
    “ Could not get unknown property ‘release’ for SigningConfig container of type org.gradle.api.internal.FactoryNamedDomainObjectContainer.”
  • That is because android studio still doesn't know what does release meant.
  • We will have to manually define it ourself like as shown below.
  • In the above code, I have added signingConfigs with the release object and few other field such as RELEASE_STORE_FILE , RELEASE_STORE_PASSWORD, RELEASE_KEY_ALIAS, RELEASE_KEY_PASSWORD which we will generating these field later.
  • At this point, if you run your application, you will get another error message saying “Could not get unknown property ‘RELEASE_STORE_FILE’” .
  • This is obvious since we do not have this field yet define yet.
  • Cool, now It is time to generate RELEASE_STORE_FILE , RELEASE_STORE_PASSWORD, RELEASE_KEY_ALIAS, RELEASE_KEY_PASSWORDand other required jks fields which define in release.

2. Generating jks file

JKS (Java KeyStore) refers to a file format used for storing private keys, public key certificates, and certificate chains. It is commonly used for signing Android applications before they can be published to platforms like the Google Play Store.

They are two ways to generate jks files, you can read more from here

  1. Using android studio GUI
  2. Using Keytool CLI
  • If you are native android developer or beginner, you could use 1st approach since it is simple and straight forward. You can follow this link for step by step process.
  • However in this process, we will be using second option to generate jks.

Using Keytool CLI

To generate jkswith CLI, run the below command base on platform that you are using.

For Linux/Mac

keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key0

For window:

keytool -genkey -v -keystore %userprofile%\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key0

Note: above command might throw “keytool command not found”, For that you will need to either set the path in environment variable or execute this code where keytool.exe is exist.

In my case It is in C:\Program Files\Java\jdk-11\bin>

Make sure set the path for jks according to your requirement. In my case, I have generate jks file in specific folder as mentioned below.

C:\Program Files\Java\jdk-11\bin> keytool -genkey -v -keystore %userprofile%\keystore\Lorta\lorta-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key0
  • When we execute the command, It will prompt you several question such as name, organization etc. screen shot attached below.

Once you answer the prompt question, It should create new jks file in the mentioned path.

Now that jks file is created. You need to mention this field in the gradle.properties file in your project android folder.

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

# New code start here
RELEASE_STORE_PASSWORD=yourpassword
RELEASE_KEY_PASSWORD=yourpassword
RELEASE_KEY_ALIAS=key0
RELEASE_STORE_FILE=C:\\Users\\kharag\\keystore\\Lorta\\lorta-keystore.jks
# New code end here

That’s it, here is the complete updated build.gradle

At this point, You can generate APK/ABB file and upload to Google PlayStore easily.

3. Generating apk/abb file

To generate build you can either use

flutter build apk // generate apk 

or

flutter build appbundle // generate appbundle

Thanks, guys, That’s all for now, Make sure to give a clap 👏 and leave some engagement. If there is any correction or feedback feel free to leave a comment as well.

If any of my shitty posts help you in any way, you can consider buying me a cup of coffee🙏.

buymeacoffee.com/codingwithtashi

Check out similar posts from CodingWithTashi. Connect me on Twitter or Linkedin.

Link and resources:

--

--