In this tutorial, we will be seeing how we can publish flutter applications with firebase to play store. Even if you are not using firebase you can follow along as there are only a few extra steps to configure firebase.
To follow along with this you will need a working flutter application, firebase project for the app and a google developer account.
Preparing the app for release
Update app manifest
Review your AndroidManifest.xml
located in app dir/android/app/src/main
Edit android:label
under application to reflect the final app name.
Change the launcher icon. Appicon.co is a good place to generate icons.
You can refer here to learn more about setting up the launcher icon.
Add required permissions for your app above application
tag.
Changing the package name
If you have package name other than
com.example.*
skip this step.
By default, your app might have a package name like com.example.*
which won’t be accepted by the play store.
Refer here to learn how to change the package name.
Updating build.gradle file
Here we are going to change the build.gradle
file located in app dir/android/app
- Add the code given below above
android
block.
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}android {
...
}
2. Under the android
block change the compileSdkVersion
and targetSdkVersion
to 29 or 30, else play store won’t accept it due to security reasons.
3. Under the android
block find buildTypes
block and change the line signingConfig signingConfigs.debug
to signingConfig signingConfigs.release
.
4. Under the android
block add these lines:
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
After doing all the above changes your build.gradle
should look similar to this (Start referring from line 27) :
Create a Keystore
If you have an existing Keystore, skip to the next step.
After executing the below command it will ask a number of questions. Fill all of those or it will give a warning that certificate is not trusted or something similar.
Default keytool password: android
On Mac/Linux, use the following command:
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
On Windows, use the following command:
keytool -genkey -v -keystore c:\Users\USER_NAME\key.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key
The above command will generate a key.jks
file in your home directory. If you get any errors it may be caused by the absence of keytool
command in your path. In that case use flutter doctor -v
and get the path under Java binary at
.
Keep this file handy, we will need it soon.
Reference the Keystore from the app
Create a file named app dir/android/key.properties
that contains a reference to your Keystore:
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>
With this we are done with the app side of things. Now lets dive into Firebase configurations.
Preparing Firebase for release
To make it work once your app is in play store we need to add release keys
from the key.jks
and app signing key
from Google play console
.
Getting the release keys
Go to the directory where you have stored your key.jks
file. Execute the following command
keytool -list -v -keystore key.jks
From here copy the SHA1 and SHA256
and add to your Firebase project settings.
Getting app signing key
- Login to your Google play console.
- Go to
Create app
and fill the required information. - Go to
Setup>App signing
. - Hit the
Create release
button. - On the new screen see top right corner
Create new release
. - Under App signing by Google Play hit
continue
. - Again go to
Setup>App signing
. Get the SHA-1 key under the App signing key certificate section.
After completing all the above steps your firebase project settings should have at least 3 SHA-1 keys (degub, release & app signing).
We are almost there…
- Now download the updated
google-services.json
and replace the older one. - Execute
flutter clean
in your project root directory. - Create a release app bundle using the command below. Make sure you are in your flutter project root directory.
flutter build appbundle --target-platform android-arm,android-arm64,android-x64
After executing the above command it will provide you with the complete path to the generated file. Copy that file to somewhere else where it is more accessible.
The Finale
- Go to your app dashboard and fill up the boring questionnaire.
- Under Grow tab, go to
Store presence>Main store listing
and provide some more information. - Go to Production, under Countries/regions select where you want your app to be accessible.
- Finally,
Create new release
upload your *.aab file.
Thanks for reading. Hope you enjoy it.
Have a lovely day. :)
Want to connect with me
GitHub: https://github.com/sarthak-2001
Linkedin: https://www.linkedin.com/in/sarthak-brahma-2001