Flutter Generate Signed aab and apk for Release from Android Studio 2024

When you create any application in Flutter and use Android Studio, you face some difficulty in creating the app bundle, so today I am going to tell you how you can bundle the app of Flutter project using Android Studio. How to create a bundle that you can upload to the Play Store!

What are we going to teach today in this article?

Today in this article, we are going to teach how to create a release bundle app of the Flutter project in Android Studio. We’re going to create the key store and password using the terminal, and also export the release file.

Here are the steps to generate aab file in Flutter

Flutter

Step 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 yourprojectname.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key0

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

Step 2:- Create a reference file to Keystore

Create a file named key.properties at [project root]>android>Right Click> File

storePassword=password from previous step
keyPassword=password from previous step
keyAlias=key0
storeFile=../../yourprojectname.jks

if you create with a different key alias, please specify it in keyAlias. For storeFile if you choose to put the Keystore file at the root of your Flutter’s project directory. This file’s path would work.

Read More :- How to Create an Intro Slider for Your App in Android Studio Java

Step 3:- Modify app/build.gradle

Open [project]/android/app/build.gradle, look for the android block and put the 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 {
           ...
      }

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

you have to replace it with the 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
         }
     }

Step 4:- Let’s sign and build the release version

Ran this Command in Terminal

flutter clean
flutter pub get
flutter build appbundle

Code and Assets from Github:- https://github.com/abidroid/t20_yt

RELATED ARTICLES