Generate signed APK/ABB in flutter
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.
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
- Configuring build.gradle
- Generating jks file
- Generating release APK/ABB
1. Configuring build.gradle
In android -> app -> build.gradle
- If you notice here, Default
buildTypes
release
signingConfig
is set todebug
by default. - To be able to generate
signed
release APK/ABB, we will need to update fromdebug
torelease
as shown below.
- You can do it by simply updating
debug
torelease
. - 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 therelease
object and few other field such asRELEASE_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_PASSWORD
and other requiredjks
fields which define inrelease
.
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
- Using android studio GUI
- 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 jks
with 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 wherekeytool.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🙏.
Check out similar posts from CodingWithTashi. Connect me on Twitter or Linkedin.
Link and resources: