How to Generate a Signed APK for Publishing on Google Play Store in Flutter: A Step-by-Step Guide with Code

Nachiketa Pandey
2 min readFeb 5, 2023

--

Publishing your Flutter app on Google Play Store requires a signed APK file. In this blog, we’ll provide a detailed step-by-step guide on how to generate a signed APK for your Flutter app. We’ll cover the creation of a keystore, signing the APK, and finalizing the process for publishing on the Play Store. This guide includes code snippets and explanations for each step, making it easy for you to follow along and successfully publish your app.

1. Update the version code and version name in pubspec.yaml

The first step is to update the version code and version name in the pubspec.yaml file. The version code should be an integer that increments with each release, while the version name is a string that represents the version in a human-readable format. Here’s an example:

version: 1.0.0+1

2. Create a Keystore File

Next, you’ll need to create a keystore file. You can do this using the keytool command in the terminal. Open the terminal and navigate to the directory where you want to store the keystore file. Then, run the following command:

keytool -genkey -v -keystore 
<keystore-name>.jks
-keyalg RSA -keysize 2048
-validity 10000 -alias
<alias-name>

Replace <keystore-name> with the name you want for the keystore file, and <alias-name> with a name for the key. You’ll be prompted to enter a password for the keystore and key, as well as information about your identity.

3. Configure Signing Settings in android/app/build.gradle

You’ll need to configure the signing settings in the android/app/build.gradle file to use the keystore file you just created. Open the file and add the following code:

def keystoreProperties =
new Properties()
def keystorePropertiesFile =
rootProject.file('key.properties')
if (keystorePropertiesFile
.exists()) {
keystoreProperties
.load(new FileInputStream(
keystorePropertiesFile))
}
android {
...
signingConfigs {
release {
keyAlias
keystoreProperties['keyAlias']
keyPassword
keystoreProperties['keyPassword']
storeFile
file(keystoreProperties['storeFile'])
storePassword
keystoreProperties['storePassword']
}
}
buildTypes {
release {
...
signingConfig
signingConfigs.release
}
}
}

4. Create a Properties File for the Keystore Information

Create a new file named key.properties in the android directory, and add the following code:

storePassword=<store-password>
keyPassword=<key-password>
keyAlias=<alias-name>
storeFile=<keystore-file-path>

Replace <store-password> and <key-password> with the passwords you entered when creating the keystore file, <alias-name> with the name of the key, and <keystore-file-path> with the path to the keystore file.

5. Generate the Signed APK

Now, you can generate the signed APK. In Android Studio, click on the Build menu and select Generate Signed APK. Fill in the required information, select the keystore file, and click on the Finish button.

--

--

Nachiketa Pandey
0 Followers

Hi! I'm Nachiketa, Flutter developer B.Tech. in Computer Science passionate about Mobile Programming with 1.5 + year experience as a Flutter developer,.