Generate Signed App Bundle (AAB) in Android Studio - Androhub

Generate Signed App Bundle in Android Studio Banner

Generate Signed App Bundle (AAB) in Android Studio

In this article, we will learn how to generate a signed app bundle (AAB) in Android Studio.

VIDEO TUTORIAL

Generate Keystore using Android Studio

Firstly, we will need Keystore to sign the app. So let’s go ahead and generate the keystore.

1. Open Android Studio and navigate to Menu -> Build -> Generate Signed Bundle/APK.

Generate Signed App Bundle KeyStore

2. Now select between the Android App Bundle or APK that you want to generate.

Select bundle or APK

3. Now we will get the below image window where it will ask you to select the existing Keystore or create a new Keystore. As we are doing for the first time we have to create a new one. Click on the Create new button.

Generate Signed Bundle Keystore Input Data

4. On clicking the Create New button another window will open where we have to input a few details that are required to generate a keystore.

Create keystore Form

5. Click on the folder icon in the Key Store path input field to select the location where you want to generate your keystore. Here we are selecting the root folder of our project. The keystone file name should be identical to your organization or the app name for which you are generating. Click on the OK button.

Select Keystore Location

Note: If you have created Keystore under your root folder then never ever commit your keystore file into your git as keystore is your sensitive file which contains classified information.

6. Now enter the rest of the information like password, alias, alias password, and certificate information as shown in the below image. Once all the details are entered click on the OK button.

Generate Keystore fill form

Note:

  1. Alias name should always be identical as per your app name so that it would be easy to figure out for which app the alias has been created.
  2. You can create multiple aliases under same keystore. That means one keystore can be used to sign multiple apps.
  3. Take the backup of Keystore and its details like passwords and alias to use them later.

Generate Keystore using Command Line

Apart from Android Studio, you can also generate a keystore from the Command Line. Open the Command prompt/Terminal and run the below command. After running the below command it will ask you to enter the same details that we did in the previous steps using Android Studio.

make sure to replace the following things before running the command:

keystore_path: actual keystore path ending with .jks like C:/Users/sample.jks.

alias_name: alias name for your app.

Note: The command will fail to execute if Java home is not set in environment variables. In this case you can go to your installed Java bin folder and execute the command from there. Because keytool will be found inside the bin folder of Java.

Generate Signed App Bundle

1. The window from where we started creating the keystone using Android Studio will now look like this as per the below image after Step 6. The key store path, passwords, and alias name will be used to generate a signed app bundle. Then click on the Next button.

Keystore and certificate generated

Note: If you have existing keystore then you can follow the Step 1 from Generate Keystore and enter the Keystore details as per above image.

2. Finally select the release Build Variant to generate the Signed App Bundle and click on the Create button.

Generate Signed Bundle select variant

3. Once the signed bundle is generated successfully you will get a popup on the bottom right as shown in the below image. Click on the locate link to open the release signed bundle path.

Generated Signed App bundle popup

In case you closed the popup or missed it then you can just open the Notifications panel from the right toolbar and you will find it there.

Generate Signed App Bundle Notification

4. Clicking on the locate link will open Explorer/Finder, where you have to click on the release folder to find the generated signed release app bundle.

Release bundle path locator

Automatically Sign Your App

We can generate the signed app bundle in the previous steps but generating it every time for the app update and testing will be a manual process and sometimes boring too. We can make this process automated by configuring it with the build process in the gradle file.

1. Open Android Studio and right-click on the app to Open Module Settings.

Open Module Settings

2. Ensure you see the image below and you are on the Signing Configs tab. Click on the + button under the Signing Configs tab to create a new Signing Configs for the release.

Signing Config Dialog

3. Now enter the new signing config name which will be release and click on the OK button.

Create New Signing Configs

4. Now make sure the newly generated signing config release is selected and enter the keystone details like keystore file path, passwords, and alias as we did in earlier steps. Then click on the Apply button followed by the OK button.

Signing Configs Details

5. The above steps will add the following code snippet into your app-level build.gralde.kts file.

6. It is not a good approach to keep your keystore details directly into your gradle file because we commit this file into the git. So we have to extract the keystone details into a property file. To do that switch to Project view and right-click on the Project name and New -> File.

Create New Properties File

7. Enter the properties file name as keystore.properties and press enter. You can take any name and make sure you are creating it under the root path.

Keystore Properties File

Note: Make sure not to add keystore.properties file also to git as this will leak keystore information.

8. Now add your keystore details to your newly created properties files as shown below.

9. Now go back to app-level build.gradle.kts file and paste the below code. This code will help us to get the keystone details from the keystore.properties file.

10. Finally link the signing config to your release build variant to automate the signing process as per the code below.

11. Now select the release build variant from the Build Variants panel which can be found on the left side toolbar.

Build Variant Selector Panel

If you don’t find the Build Variant panel then navigate to Menu -> View -> Tool Windows -> Build Variants.

Build Variant Option menu

12. On selecting the release build variant the app configuration icon shouldn’t have a cross icon at the top as shown in the below image. If it’s there that means the signing config process is not configured properly.

Run configuration Error

If the signing config is successful then you will not see any cross icon on the app configuration icon similar to the debug variant.

Run Configuration Success

13. Now to generate automated signed bundles navigate to Menu -> Build -> Build Bundle(s)/APK(s) and select the APK or Bundle as per requirement.

Build Bundle Menu Option

14. Using this automated signing process will generate a release-signed app bundle or APK under the build folder instead of the release. So the new path will be build/outputs/.

Release bundle output path

Benefits of Automated Process

Using the Automated Signing Process will make your life easy in the following ways:

1. Never worry about remembering keystore details like passwords, and aliases.

2. You can directly run the release build variant and test to check if every functionality is working as expected or not. Because sometimes the app might crash on release builds but not on debug builds.

3. Generate release bundles in just one click.

Ignore Files in Git

Ignore Keystore related files in git so that these files won’t be tracked and will not be added to your git. To do that open the .gitignore file under your project root directory and add the properties and keystore file to it.

Thanks😊

 

Post comment

Your email address will not be published. Required fields are marked *