Sign and build a Flutter app in Windows.

Ariel Mejia Dev
Ariel Mejia Dev
Published in
4 min readAug 19, 2019

In this post we are going to asume that your app is ready for production,

Now to publish on playstore is not necesary but could be a great feature if you add a custom icon to your app “flutter launcher icons“ package provides a very easy way to handle icons, Here is a link for the documentation: click here.

Maybe you will change the name of your app in the device, I have a post to change the app name here.

And add internet permissions if your app requires data from an API that is the case in most of them, I have a post to add the internet permission here.

Next you need to sign your app.

Sign your app.

It NECESARY to open your “cmd” as administrator

Run:

flutter doctor -v

This command will output something like this:

In flutter documentation it recommend to use that fully qualified path replacing java (at the end) with keytool , but that not necesary works on any Windows device, so a very easy way to solve this problem is to go to the Java binary directory.

We have two ways to do this step:

From Visual GUI

you can go to the directory and there open a “terminal” if you have Cmder on your Windows machine it will help but even if you do not have it you can use cmd to open a “cmd” there.

From Terminal

The other way is to go from your terminal to this folder with a command like this, this command works if you open a new “cmd” window as administrator:

cd ../../cd Program Files/Android/Android Studio/jre/bin

If you are in other location you only need to make some cd ../ until you go to de “C://” directory.

Run a sign command

Then in your “Java/bin” directory just run the command to sign your app from Flutter documentation:

keytool -genkey -v -keystore c:/Users/USER_NAME/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

This command prompt some questions like store password, key password, organization name, country, state, etc. So only answer this questions and remember or write the passwords in a safe place.

Reference the Keystore

Open your favorite code editor and on the app root folder as app directory go to android folder and there create a file named key.properties, and paste this code lines in the file:

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>

This file need to be filled with the answers of the sign command, example:

storePassword=12345678
keyPassword=12345678
keyAlias=key
storeFile=key.jks

Store file, needs the value where you store the key.jks file, you can add the key to your android/app/ directory to make more easy the path to only use the file name, but you must add the file path into your .gitignore file to not upload this file in your Github account because it is some risky.

Configure the gradle

Go to your app root directory in android folder then go to app folder now you will see a file named build.gradle, with the code editor we are going to edit this file, go to:

android {

and this code previously to be like this:

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

android {

Then replace:

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
}
}

with:

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

Build the app release

Go to the project folder and open the terminal, if you use VScode you can open the terminal directly there, with “terminal” plugin or in top menu in terminal menu, click the option “new terminal”, in any other text editor exists a way to open a terminal inside the current project, now in terminal write the command:

flutter build appbundle

Now you can search on your project root folder in /build/app/outputs/bundle/release/app.aab, this “app.aab” file is the file that you need to upload to the playstore in console this is the link.

To publish the app in the playstore I have a post here.

Thanks and happy coding.

--

--

Ariel Mejia Dev
Ariel Mejia Dev

Fullstack Web/Mobile Developer and Laravel enthusiast.