DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Step-by-step to publish your flutter project as Android App Bundle
Teerasej Jiraphatchandej
Teerasej Jiraphatchandej

Posted on • Updated on

Step-by-step to publish your flutter project as Android App Bundle

The Flutter's official instruction is suitable for a start. But I want to note my step-by-step here. So you might not need to guess about the file's path.

1. Create your Keystore

Keystore is the file you should have to sign your AAB file.

Run the following command in Terminal at your project's root directory.

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

After entering this command, you will be asked to fill key's password and some information.

Please pay attention to the following options:

  • -keystore is the file's name and where it will be created. upload-keystore.jks will be made at your project's root directory. The original instruction: ~/upload-keystore.jks will put your Keystore file in the user's root directory.
  • -alias will be your key's alias name. You will need to use it later.

2. Create a reference file to Keystore

Create a file named key.properties at [project root]/android/

storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=upload
storeFile=../../upload-keystore.jks
Enter fullscreen mode Exit fullscreen mode
  • if you create with different key alias, please specify it in keyAlias.
  • For storeFile if you choose to put Keystore file at the root of your Flutter's project directory. This file's path would work.

3. Modify app/build.gradle

Now, we have to modify build.gradle. So Flutter can use it to sign and generate an AAB file.

Load keystore's properties

Open [project]/android/app/build.gradle, look for android block, and put following code at the top of its.

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

   android {
         ...
   }

Enter fullscreen mode Exit fullscreen mode

Replace buildTypes block

find buildTypes block. it should look like the below:

   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
       }
   }
Enter fullscreen mode Exit fullscreen mode

you have to replace it with following code:

   signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }
Enter fullscreen mode Exit fullscreen mode

4. Let's sign and build the release version

After you modified build.gradle file, you should run:

flutter clean
Enter fullscreen mode Exit fullscreen mode

So you can try to build the AAB file:

flutter build appbundle
Enter fullscreen mode Exit fullscreen mode

If the build has been successful, you will see the AAB's file path on the Terminal's console.

Top comments (0)

🌚 Life is too short to browse without dark mode